# HG changeset patch # User Binki # Date 2009-11-04 20:26:37 # Node ID 00963547e6b95caee859301207ee24c800068848 # Parent 8af872d2fe8d6187d06f247c7d30cc44270983bb basic remoteio socket client diff --git a/src/common/remoteio.c b/src/common/remoteio.c --- a/src/common/remoteio.c +++ b/src/common/remoteio.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef WINDOWS #include #include @@ -313,20 +314,80 @@ int _remoteio_sock_open(struct remoteio int _remoteio_sock_read(struct remoteio *rem, void *buf, size_t len, size_t *bytesread) { + ssize_t readrtn; - return 1; + readrtn = read(rem->sock, buf, len); + /* + The following is valid for blocking sockets: + */ + if(readrtn == -1) + { + /* + in this case, we may have been interrupted by a signal and errno == EINTR + or the connection was reset and errno = ECONNRESET + + Some of these are not error conditions: + */ + perror("read"); + *bytesread = 0; + + if(errno != EINTR) + { + fprintf(stderr, "error reading socket in remoteio_sock_read\n"); + return 1; + } + + return 0; + } + + *bytesread = readrtn; + if(!readrtn) + { + /* + means EOF except when FD is in ``message-nondiscard'' or ``message-discard'' + modes. + */ + return 1; + } + + return 0; } int _remoteio_sock_write(struct remoteio *rem, void *buf, size_t len, size_t *byteswritten) { + ssize_t writertn; - return 1; + writertn = write(rem->sock, buf, len); + + if(writertn == -1) + { + perror("write"); + if(errno != EINTR) + { + fprintf(stderr, "error writing to socket in remoteio_sock_write()\n"); + return 1; + } + } + + *byteswritten = writertn; + if(!writertn) + { + /* + should we consider this an error? I'm pretty + sure we should :-/ + */ + fprintf(stderr, "write() returned 0 in remoteio_sock_write()\n"); + return 1; + } + + return 0; } int _remoteio_sock_close(struct remoteio *rem) { + close(rem->sock); - return 1; + return 0; } #endif