summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-10-23 16:05:44 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-10-23 16:05:44 +0800
commitc4b42e5fa1152305680c18009ae6e80467273e41 (patch)
tree1b0c98e7261a3bed11552346706124b5c1f785ac
parent354b9f1112370fb68df58526dc7f72cc86208899 (diff)
downloadpttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.tar
pttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.tar.gz
pttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.tar.bz2
pttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.tar.lz
pttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.tar.xz
pttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.tar.zst
pttbbs-c4b42e5fa1152305680c18009ae6e80467273e41.zip
* add tosend/torecv because they can take additional flags (helpful to writing without SIGPIPE)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@4969 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/common/sys/net.c38
-rw-r--r--pttbbs/include/cmsys.h2
2 files changed, 40 insertions, 0 deletions
diff --git a/pttbbs/common/sys/net.c b/pttbbs/common/sys/net.c
index c8ae9e50..fe6c216d 100644
--- a/pttbbs/common/sys/net.c
+++ b/pttbbs/common/sys/net.c
@@ -265,6 +265,44 @@ int towrite(int fd, const void *buf, int len)
}
/**
+ * same as recv(2), but recv until exactly size len
+ */
+int torecv(int fd, void *buf, int len, int flag)
+{
+ int s;
+ for( s = 0 ; len > 0 ; )
+ if( (s = recv(fd, buf, len, flag)) <= 0 ) {
+ if (s < 0 && (errno == EINTR || errno == EAGAIN))
+ continue;
+ // XXX we define toread/towrite as '-1 for EOF and error'.
+ return -1; // s;
+ }else{
+ buf += s;
+ len -= s;
+ }
+ return s;
+}
+
+/**
+ * similiar to send(2), but send until exactly size len
+ */
+int tosend(int fd, const void *buf, int len, int flag)
+{
+ int s;
+ for( s = 0 ; len > 0 ; )
+ if( (s = send(fd, buf, len, flag)) <= 0){
+ if (s < 0 && (errno == EINTR || errno == EAGAIN))
+ continue;
+ // XXX we define toread/towrite as '-1 for EOF and error'.
+ return -1; // s;
+ }else{
+ buf += s;
+ len -= s;
+ }
+ return s;
+}
+
+/**
* fd sharing by piaip
*/
diff --git a/pttbbs/include/cmsys.h b/pttbbs/include/cmsys.h
index 7704191c..a4add657 100644
--- a/pttbbs/include/cmsys.h
+++ b/pttbbs/include/cmsys.h
@@ -81,6 +81,8 @@ extern int toconnect(const char *addr);
extern int toconnectex(const char *addr, int timeout);
extern int toread (int fd, void *buf, int len);
extern int towrite (int fd, const void *buf, int len);
+extern int torecv (int fd, void *buf, int len, int flag);
+extern int tosend (int fd, const void *buf, int len, int flag);
extern int send_remote_fd(int tunnel, int fd);
extern int recv_remote_fd(int tunnel, const char *tunnel_path);