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 |
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 |
|
|
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 |
{ |
{ |
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 ∈ |
return ∈ |
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 |
|
|
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 |
} |
} |