350 #define BLOCKING_IO_RETURN_INT(FD, FUNC) { \ 351 int ret; \ 352 threadEntry_t self; \ 353 fdEntry_t *fdEntry = getFdEntry(FD); \ 354 if (fdEntry == NULL) { \ 355 errno = EBADF; \ 356 return -1; \ 357 } \ 358 do { \ 359 startOp(fdEntry, &self); \ 360 ret = FUNC; \ 361 endOp(fdEntry, &self); \ 362 } while (ret == -1 && errno == EINTR); \ 363 return ret; \ 364 } 365 366 int NET_Read(int s, void* buf, size_t len) { 367 BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) ); 368 } 369 370 int NET_ReadV(int s, const struct iovec * vector, int count) { 371 BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) ); 372 } 373 374 int NET_RecvFrom(int s, void *buf, int len, unsigned int flags, 375 struct sockaddr *from, socklen_t *fromlen) { 376 BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, fromlen) ); 377 } 378 379 int NET_Send(int s, void *msg, int len, unsigned int flags) { 380 BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) ); 381 } 382 383 int NET_WriteV(int s, const struct iovec * vector, int count) { 384 BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) ); 385 } 386 387 int NET_SendTo(int s, const void *msg, int len, unsigned int 388 flags, const struct sockaddr *to, int tolen) { 389 BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) ); | 350 #define BLOCKING_IO_RETURN_INT(FD, FUNC) { \ 351 int ret; \ 352 threadEntry_t self; \ 353 fdEntry_t *fdEntry = getFdEntry(FD); \ 354 if (fdEntry == NULL) { \ 355 errno = EBADF; \ 356 return -1; \ 357 } \ 358 do { \ 359 startOp(fdEntry, &self); \ 360 ret = FUNC; \ 361 endOp(fdEntry, &self); \ 362 } while (ret == -1 && errno == EINTR); \ 363 return ret; \ 364 } 365 366 int NET_Read(int s, void* buf, size_t len) { 367 BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) ); 368 } 369 370 int NET_NonBlockingRead(int s, void* buf, size_t len) { 371 BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT) ); 372 } 373 374 int NET_ReadV(int s, const struct iovec * vector, int count) { 375 BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) ); 376 } 377 378 int NET_RecvFrom(int s, void *buf, int len, unsigned int flags, 379 struct sockaddr *from, socklen_t *fromlen) { 380 BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, fromlen) ); 381 } 382 383 int NET_Send(int s, void *msg, int len, unsigned int flags) { 384 BLOCKING_IO_RETURN_INT( s, send(s, msg, len, flags) ); 385 } 386 387 int NET_WriteV(int s, const struct iovec * vector, int count) { 388 BLOCKING_IO_RETURN_INT( s, writev(s, vector, count) ); 389 } 390 391 int NET_SendTo(int s, const void *msg, int len, unsigned int 392 flags, const struct sockaddr *to, int tolen) { 393 BLOCKING_IO_RETURN_INT( s, sendto(s, msg, len, flags, to, tolen) ); |