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