+
+ return StrLength(Ret);
+}
+
+
+int client_write(StrBuf *ThisBuf)
+{
+ wcsession *WCC = WC;
+ const char *ptr, *eptr;
+ long count;
+ ssize_t res = 0;
+ fd_set wset;
+ int fdflags;
+
+ ptr = ChrPtr(ThisBuf);
+ count = StrLength(ThisBuf);
+ eptr = ptr + count;
+
+ fdflags = fcntl(WC->Hdr->http_sock, F_GETFL);
+
+ while ((ptr < eptr) && (WCC->Hdr->http_sock != -1)) {
+ if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
+ FD_ZERO(&wset);
+ FD_SET(WCC->Hdr->http_sock, &wset);
+ if (select(WCC->Hdr->http_sock + 1, NULL, &wset, NULL, NULL) == -1) {
+ syslog(LOG_INFO, "client_write: Socket select failed (%s)\n", strerror(errno));
+ return -1;
+ }
+ }
+
+ if ((WCC->Hdr->http_sock == -1) ||
+ (res = write(WCC->Hdr->http_sock,
+ ptr,
+ count)) == -1) {
+ syslog(LOG_INFO, "client_write: Socket write failed (%s)\n", strerror(errno));
+ wc_backtrace(LOG_INFO);
+ return res;
+ }
+ count -= res;
+ ptr += res;
+ }
+ return 0;
+}
+
+
+int
+read_serv_chunk(
+
+ StrBuf *Buf,
+ size_t total_len,
+ size_t *bytes_read
+ )
+{
+ int rc;
+ int ServerRc;
+ wcsession *WCC = WC;
+
+ serv_printf("READ "SIZE_T_FMT"|"SIZE_T_FMT, *bytes_read, total_len-(*bytes_read));
+ if ( (rc = StrBuf_ServGetln(Buf) > 0) &&
+ (ServerRc = GetServerStatus(Buf, NULL), ServerRc == 6) )
+ {
+ size_t this_block = 0;
+
+ if (rc < 0)
+ return rc;
+
+ StrBufCutLeft(Buf, 4);
+ this_block = StrTol(Buf);
+ rc = StrBuf_ServGetBLOBBuffered(WCC->WBuf, this_block);
+ if (rc < 0) {
+ syslog(LOG_INFO, "Server connection broken during download\n");
+ wc_backtrace(LOG_INFO);
+ if (WCC->serv_sock > 0) close(WCC->serv_sock);
+ WCC->serv_sock = (-1);
+ WCC->connected = 0;
+ WCC->logged_in = 0;
+ return rc;