/[rdesktop]/sourceforge.net/trunk/rdesktop/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 /sourceforge.net/trunk/rdesktop/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 192 by matthewc, Tue Sep 24 07:59:14 2002 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 31  Line 31 
31  static int sock;  static int sock;
32  static struct stream in;  static struct stream in;
33  static struct stream out;  static struct stream out;
34    extern int tcp_port_rdp;
35    
36  /* Initialise TCP transport data packet */  /* Initialise TCP transport data packet */
37  STREAM  STREAM
# Line 56  tcp_send(STREAM s) Line 57  tcp_send(STREAM s)
57    
58          while (total < length)          while (total < length)
59          {          {
60                  sent = write(sock, s->data + total, length - total);                  sent = send(sock, s->data + total, length - total, 0);
   
61                  if (sent <= 0)                  if (sent <= 0)
62                  {                  {
63                          STATUS("write: %s\n", strerror(errno));                          error("send: %s\n", strerror(errno));
64                          return;                          return;
65                  }                  }
66    
# Line 72  tcp_send(STREAM s) Line 72  tcp_send(STREAM s)
72  STREAM  STREAM
73  tcp_recv(int length)  tcp_recv(int length)
74  {  {
75          int ret, rcvd = 0;          int rcvd = 0;
         struct timeval tv;  
         fd_set rfds;  
76    
77          if (length > in.size)          if (length > in.size)
78          {          {
# Line 86  tcp_recv(int length) Line 84  tcp_recv(int length)
84    
85          while (length > 0)          while (length > 0)
86          {          {
87                  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);  
88    
89                  if (ret)                  rcvd = recv(sock, in.end, length, 0);
90                    if (rcvd == -1)
91                  {                  {
92                          rcvd = read(sock, in.end, length);                          error("recv: %s\n", strerror(errno));
93                            return NULL;
                         if (rcvd <= 0)  
                         {  
                                 STATUS("read: %s\n", strerror(errno));  
                                 return NULL;  
                         }  
   
                         in.end += rcvd;  
                         length -= rcvd;  
94                  }                  }
95    
96                    in.end += rcvd;
97                    length -= rcvd;
98          }          }
99    
100          return &in;          return &in;
# Line 123  tcp_connect(char *server) Line 110  tcp_connect(char *server)
110    
111          if ((nslookup = gethostbyname(server)) != NULL)          if ((nslookup = gethostbyname(server)) != NULL)
112          {          {
113                  memcpy(&servaddr.sin_addr, nslookup->h_addr,                  memcpy(&servaddr.sin_addr, nslookup->h_addr, sizeof(servaddr.sin_addr));
                        sizeof(servaddr.sin_addr));  
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    
127          servaddr.sin_family = AF_INET;          servaddr.sin_family = AF_INET;
128          servaddr.sin_port = htons(TCP_PORT_RDP);          servaddr.sin_port = htons(tcp_port_rdp);
129    
130          if (connect          if (connect(sock, (struct sockaddr *) &servaddr, sizeof(struct sockaddr)) < 0)
             (sock, (struct sockaddr *) &servaddr,  
              sizeof(struct sockaddr)) < 0)  
131          {          {
132                  STATUS("connect: %s\n", strerror(errno));                  error("connect: %s\n", strerror(errno));
133                  close(sock);                  close(sock);
134                  return False;                  return False;
135          }          }
136    
137          setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *) &true,          setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *) &true, sizeof(true));
                    sizeof(true));  
138    
139          in.size = 4096;          in.size = 4096;
140          in.data = xmalloc(in.size);          in.data = xmalloc(in.size);
# Line 164  tcp_connect(char *server) Line 147  tcp_connect(char *server)
147    
148  /* Disconnect on the TCP layer */  /* Disconnect on the TCP layer */
149  void  void
150  tcp_disconnect()  tcp_disconnect(void)
151  {  {
152          close(sock);          close(sock);
153  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26