comparison src/win32/libc_interface.c @ 13200:33bef17125c2

[gaim-migrate @ 15563] This is the soon-to-be-infamous nonblocking network activity patch that I've been working on. Feel free to yell at me if this makes you unhappy. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 09 Feb 2006 04:17:56 +0000
parents 13276711babc
children b04212d6b115
comparison
equal deleted inserted replaced
13199:d8f238864c88 13200:33bef17125c2
274 * We need to figure out whether fd is a file or socket handle. 274 * We need to figure out whether fd is a file or socket handle.
275 */ 275 */
276 int wgaim_read(int fd, void *buf, unsigned int size) { 276 int wgaim_read(int fd, void *buf, unsigned int size) {
277 int ret; 277 int ret;
278 278
279 if( wgaim_is_socket(fd) ) { 279 if(wgaim_is_socket(fd)) {
280 if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { 280 if((ret = recv(fd, buf, size, 0)) == SOCKET_ERROR) {
281 errno = WSAGetLastError(); 281 errno = WSAGetLastError();
282 if(errno == WSAEWOULDBLOCK)
283 errno = EAGAIN;
282 return -1; 284 return -1;
283 } 285 }
284 #if 0 286 #if 0
285 else if( ret == 0 ) { 287 else if( ret == 0 ) {
286 /* connection has been gracefully closed */ 288 /* connection has been gracefully closed */
290 #endif 292 #endif
291 else { 293 else {
292 /* success reading socket */ 294 /* success reading socket */
293 return ret; 295 return ret;
294 } 296 }
295 } 297 } else {
296 else {
297 /* fd is not a socket handle.. pass it off to read */ 298 /* fd is not a socket handle.. pass it off to read */
298 return read(fd, buf, size); 299 return read(fd, buf, size);
299 } 300 }
300 } 301 }
301 302
302 int wgaim_write(int fd, const void *buf, unsigned int size) { 303 int wgaim_write(int fd, const void *buf, unsigned int size) {
303 int ret; 304 int ret;
304 305
305 if( wgaim_is_socket(fd) ) { 306 if(wgaim_is_socket(fd)) {
306 if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { 307 if((ret = send(fd, buf, size, 0)) == SOCKET_ERROR) {
307 errno = WSAGetLastError(); 308 errno = WSAGetLastError();
308 return -1; 309 if(errno == WSAEWOULDBLOCK)
309 } 310 errno = EAGAIN;
310 else { 311 return -1;
312 } else {
311 /* success */ 313 /* success */
312 return ret; 314 return ret;
313 } 315 }
314 } 316 } else
315 else
316 return write(fd, buf, size); 317 return write(fd, buf, size);
317 } 318 }
318 319
319 int wgaim_recv(int fd, void *buf, size_t len, int flags) { 320 int wgaim_recv(int fd, void *buf, size_t len, int flags) {
320 int ret; 321 int ret;
321 322
322 if ((ret = recv(fd, buf, len, flags)) == SOCKET_ERROR) { 323 if((ret = recv(fd, buf, len, flags)) == SOCKET_ERROR) {
323 errno = WSAGetLastError(); 324 errno = WSAGetLastError();
325 if(errno == WSAEWOULDBLOCK)
326 errno = EAGAIN;
324 return -1; 327 return -1;
325 } else { 328 } else {
326 return ret; 329 return ret;
327 } 330 }
328 } 331 }