Changeset 474:5da95acd7b11 in verona
- Timestamp:
- May 3, 2012 1:43:14 PM (14 months ago)
- Branch:
- default
- File:
-
- 1 edited
-
phapi/ph_socks_rtp.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
phapi/ph_socks_rtp.c
r472 r474 36 36 #ifndef WIN32 37 37 #define closesocket close 38 #else 39 static int 40 socknonblocking(SOCKET sock, int yes) 41 { 42 return sockioctl(sock, FIONBIO, (char *)&yes); 43 } 44 45 static int 46 recvAll(SOCKET sock, char* buf, size_t s) 47 { 48 // the socket is in non blocking mode in WIN32 49 int count = 100; 50 int total = 0; 51 52 while(total < (int) s && count--) { 53 int res = recv(sock, buf, s, 0); 54 55 if (res == SOCKET_ERROR) { 56 int err = WSAGetLastError(); 57 58 if (err == WSAEWOULDBLOCK) { 59 continue; 60 } 61 return -1; 62 } 63 toal += res; 64 buf += res; 65 s -= res; 66 67 } 68 69 return total; 70 } 71 #endif 72 73 #ifndef MSG_NOSIGNAL 74 #define MSG_NOSIGNAL 0 38 75 #endif 39 76 … … 96 133 connreq.port = as_sin(&sk->addr).sin_port; 97 134 98 res = send(sk->socket, &connreq, 10, 0);135 res = send(sk->socket, &connreq, 10, MSG_DONTWAIT|MSG_NOSIGNAL); 99 136 if (res != 10) 100 137 return -1; … … 106 143 plen = htonl(slen); 107 144 108 res = send(sk->socket, &plen, 4, 0);145 res = send(sk->socket, &plen, 4, MSG_DONTWAIT|MSG_NOSIGNAL); 109 146 if (res != 4) 110 147 return -1; 111 res = send(sk->socket, m->b_rptr, slen, MSG_DONTWAIT );148 res = send(sk->socket, m->b_rptr, slen, MSG_DONTWAIT|MSG_NOSIGNAL); 112 149 return res; 113 150 } … … 141 178 return 0; 142 179 143 180 #ifdef WIN32 181 res = recvAll(sk->socket, m->b_wptr, expectlen); 182 #else 144 183 res = recv(sk->socket, m->b_wptr, expectlen, 0); 184 #endif 145 185 if (res <= 0) 146 186 return res; … … 203 243 struct in_addr ina; 204 244 205 ret = send(sk->socket, msg1, 3, 0);245 ret = send(sk->socket, msg1, 3, MSG_NOSIGNAL); 206 246 if (ret != 3) 207 247 return -1; … … 223 263 req.dport = as_sin(&sk->addr).sin_port; 224 264 225 ret = send(sk->socket, &req, sizeof(req), 0);265 ret = send(sk->socket, &req, sizeof(req), MSG_NOSIGNAL); 226 266 if (ret != sizeof(req)) 227 267 return -1; … … 240 280 return -1; 241 281 242 ret = recv(sk->socket, &resp.destip, 6, 0);282 ret = recv(sk->socket, &resp.destip, 6, MSG_NOSIGNAL); 243 283 if (ret != 6) 244 284 return 0; … … 246 286 sk->publicip = resp.destip; 247 287 sk->publicport = resp.dport; 288 289 #ifdef WIN32 290 /* make socket non-blocking */ 291 { 292 char yes = 1; 293 294 sockioctl(sk->socket, FIONBIO, (char *)&yes); 295 } 296 #endif 297 #ifdef APPLE 298 { 299 int set = 1; 300 setsockopt(sk->socket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); 301 } 302 #endif 303 248 304 249 305 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
