/[rdesktop]/jpeg/rdesktop/trunk/tcp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/tcp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by matty, Sat Jan 6 03:47:04 2001 UTC revision 33 by matty, Sat Sep 15 12:34:34 2001 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - TCP layer     Protocol services - TCP layer
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2001
5        
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 56  tcp_send(STREAM s) Line 56  tcp_send(STREAM s)
56    
57          while (total < length)          while (total < length)
58          {          {
59                  sent = write(sock, s->data + total, length - total);                  sent = send(sock, s->data + total, length - total, 0);
   
60                  if (sent <= 0)                  if (sent <= 0)
61                  {                  {
62                          STATUS("write: %s\n", strerror(errno));                          error("send: %s\n", strerror(errno));
63                          return;                          return;
64                  }                  }
65    
# Line 72  tcp_send(STREAM s) Line 71  tcp_send(STREAM s)
71  STREAM  STREAM
72  tcp_recv(int length)  tcp_recv(int length)
73  {  {
74          int ret, rcvd = 0;          int rcvd = 0;
         struct timeval tv;  
         fd_set rfds;  
75    
76          if (length > in.size)          if (length > in.size)
77          {          {
# Line 86  tcp_recv(int length) Line 83  tcp_recv(int length)
83    
84          while (length > 0)          while (length > 0)
85          {          {
86                  ui_process_events();                  ui_select(sock);
   
                 FD_ZERO(&rfds);  
                 FD_SET(sock, &rfds);  
                 tv.tv_sec = 0;  
                 tv.tv_usec = 100;  
   
                 ret = select(sock + 1, &rfds, NULL, NULL, &tv);  
87    
88                  if (ret)                  rcvd = recv(sock, in.end, length, 0);
89                    if (rcvd == -1)
90                  {                  {
91                          rcvd = read(sock, in.end, length);                          error("recv: %s\n", strerror(errno));
92                            return NULL;
                         if (rcvd <= 0)  
                         {  
                                 STATUS("read: %s\n", strerror(errno));  
                                 return NULL;  
                         }  
   
                         in.end += rcvd;  
                         length -= rcvd;  
93                  }                  }
94    
95                    in.end += rcvd;
96                    length -= rcvd;
97          }          }
98    
99          return &in;          return &in;
# Line 128  tcp_connect(char *server) Line 114  tcp_connect(char *server)
114          }          }
115          else if (!(servaddr.sin_addr.s_addr = inet_addr(server)))          else if (!(servaddr.sin_addr.s_addr = inet_addr(server)))
116          {          {
117                  STATUS("%s: unable to resolve host\n", server);                  error("%s: unable to resolve host\n", server);
118                  return False;                  return False;
119          }          }
120    
121          if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)          if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
122          {          {
123                  STATUS("socket: %s\n", strerror(errno));                  error("socket: %s\n", strerror(errno));
124                  return False;                  return False;
125          }          }
126    
# Line 145  tcp_connect(char *server) Line 131  tcp_connect(char *server)
131              (sock, (struct sockaddr *) &servaddr,              (sock, (struct sockaddr *) &servaddr,
132               sizeof(struct sockaddr)) < 0)               sizeof(struct sockaddr)) < 0)
133          {          {
134                  STATUS("connect: %s\n", strerror(errno));                  error("connect: %s\n", strerror(errno));
135                  close(sock);                  close(sock);
136                  return False;                  return False;
137          }          }

Legend:
Removed from v.25  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC 1.1.26