]> code.citadel.org Git - citadel.git/blobdiff - citadel/clientsocket.c
Revert "Replaced client_read() with socket_read_blob() in serv_network.c"
[citadel.git] / citadel / clientsocket.c
index 594b5eb9664d969e8f8b2988e66a2909b9e99439..8052e24e4ac8ced4b22747d4029f5ba3fa313e4d 100644 (file)
@@ -147,6 +147,28 @@ int socket_read_blob(int *Socket, StrBuf * Target, int bytes, int timeout)
 }
 
 
+int sock_read_to(int *sock, char *buf, int bytes, int timeout,
+                int keep_reading_until_full)
+{
+       CitContext *CCC = MyContext();
+       int rc;
+
+       FlushStrBuf(CCC->MigrateBuf);
+       rc = socket_read_blob(sock, CCC->sMigrateBuf, bytes, timeout);
+       if (rc < 0) {
+               *buf = '\0';
+               return rc;
+       } else {
+               if (StrLength(CCC->MigrateBuf) < bytes)
+                       bytes = StrLength(CCC->MigrateBuf);
+               memcpy(buf, ChrPtr(CCC->MigrateBuf), bytes);
+
+               FlushStrBuf(CCC->MigrateBuf);
+               return rc;
+       }
+}
+
+
 int CtdlSockGetLine(int *sock, StrBuf * Target, int nSec)
 {
        CitContext *CCC = MyContext();
@@ -193,6 +215,18 @@ int sock_getln(int *sock, char *buf, int bufsize)
 }
 
 
+/*
+ * sock_read() - input binary data from socket.
+ * Returns the number of bytes read, or -1 for error.
+ */
+INLINE int sock_read(int *sock, char *buf, int bytes,
+                    int keep_reading_until_full)
+{
+       return sock_read_to(sock, buf, bytes, CLIENT_TIMEOUT,
+                           keep_reading_until_full);
+}
+
+
 /*
  * sock_write() - send binary to server.
  * Returns the number of bytes written, or -1 for error.