]> code.citadel.org Git - citadel.git/blobdiff - citadel/clientsocket.c
Use IOBuffer with its StrBuf + const char* inside instead of having two of them
[citadel.git] / citadel / clientsocket.c
index 54bceb7a5f4468ffbd91a1f06071a925e3e47765..49cfd54ef7c68fa03b590aad4347549e13213ea5 100644 (file)
@@ -136,8 +136,8 @@ int socket_read_blob(int *Socket, StrBuf * Target, int bytes, int timeout)
 
 
        retval = StrBufReadBLOBBuffered(Target,
-                                       CCC->sReadBuf,
-                                       &CCC->sPos,
+                                       CCC->SBuf.Buf,
+                                       &CCC->SBuf.ReadWritePointer,
                                        Socket, 1, bytes, O_TERM, &Error);
        if (retval < 0) {
                CtdlLogPrintf(CTDL_CRIT,
@@ -147,28 +147,6 @@ 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();
@@ -177,8 +155,8 @@ int CtdlSockGetLine(int *sock, StrBuf * Target, int nSec)
 
        FlushStrBuf(Target);
        rc = StrBufTCP_read_buffered_line_fast(Target,
-                                              CCC->sReadBuf,
-                                              &CCC->sPos,
+                                              CCC->SBuf.Buf,
+                                              &CCC->SBuf.ReadWritePointer,
                                               sock, nSec, 1, &Error);
        if ((rc < 0) && (Error != NULL))
                CtdlLogPrintf(CTDL_CRIT,
@@ -215,23 +193,13 @@ 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.
  */
-int sock_write(int *sock, const char *buf, int nbytes)
+int sock_write(int *sock, const char *buf, int nbytes) 
+{ return sock_write_timeout(sock, buf, nbytes, 50); }
+int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout)
 {
        int nSuccessLess = 0;
        int bytes_written = 0;
@@ -239,7 +207,6 @@ int sock_write(int *sock, const char *buf, int nbytes)
        fd_set rfds;
         int fdflags;
        int IsNonBlock;
-       int timeout = 50;
        struct timeval tv;
        int selectresolution = 100;