changeset 1399:cea7268ebb05

Removed the old sock_handler_* API
author Jorge Arellano Cid <jcid@dillo.org>
date Sun, 01 Nov 2009 16:31:59 -0300
parents b0aec637cdc0
children af8b2297ff11
files dpi/dpiutil.c dpi/dpiutil.h
diffstat 2 files changed, 0 insertions(+), 164 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/dpiutil.c	Sun Nov 01 16:31:59 2009 -0300
+++ b/dpi/dpiutil.c	Sun Nov 01 16:31:59 2009 -0300
@@ -163,130 +163,3 @@
    return url;
 }
 
-
-/* Streamed Sockets API (not mandatory)  ----------------------------------*/
-
-/*
- * Create and initialize the SockHandler structure
- */
-SockHandler *sock_handler_new(int fd_in, int fd_out, int flush_sz)
-{
-   SockHandler *sh = dNew(SockHandler, 1);
-
-   /* init descriptors and streams */
-   sh->fd_in  = fd_in;
-   sh->fd_out = fd_out;
-   sh->out = fdopen(fd_out, "w");
-
-   /* init buffer */
-   sh->buf_max = 8 * 1024;
-   sh->buf = dNew(char, sh->buf_max);
-   sh->buf_sz = 0;
-   sh->flush_sz = flush_sz;
-
-   return sh;
-}
-
-/*
- * Streamed write to socket
- * Return: 0 on success, 1 on error.
- */
-int sock_handler_write(SockHandler *sh, int flush,
-                       const char *Data, size_t DataSize)
-{
-   int ret = 1;
-
-   /* append to buf */
-   while (sh->buf_max < sh->buf_sz + DataSize) {
-      sh->buf_max <<= 1;
-      sh->buf = dRealloc(sh->buf, sh->buf_max);
-   }
-   memcpy(sh->buf + sh->buf_sz, Data, DataSize);
-   sh->buf_sz += DataSize;
-/*
-   MSG("sh->buf=%p, sh->buf_sz=%d, sh->buf_max=%d, sh->flush_sz=%d\n",
-       sh->buf, sh->buf_sz, sh->buf_max, sh->flush_sz);
-*/
-/**/
-#if 0
-{
-   uint_t i;
-   /* Test dpip's stream handling by chopping data into characters */
-   for (i = 0; i < sh->buf_sz; ++i) {
-      fputc(sh->buf[i], sh->out);
-      fflush(sh->out);
-      usleep(50);
-   }
-   if (i == sh->buf_sz) {
-      sh->buf_sz = 0;
-      ret = 0;
-   }
-}
-#else
-   /* flush data if necessary */
-   if (flush || sh->buf_sz >= sh->flush_sz) {
-      if (sh->buf_sz && fwrite (sh->buf, sh->buf_sz, 1, sh->out) != 1) {
-         perror("[sock_handler_write]");
-      } else {
-         fflush(sh->out);
-         sh->buf_sz = 0;
-         ret = 0;
-      }
-
-   } else {
-      ret = 0;
-   }
-#endif
-   return ret;
-}
-
-/*
- * Convenience function.
- */
-int sock_handler_write_str(SockHandler *sh, int flush, const char *str)
-{
-   return sock_handler_write(sh, flush, str, strlen(str));
-}
-
-/*
- * Return a newlly allocated string with the contents read from the socket.
- */
-char *sock_handler_read(SockHandler *sh)
-{
-   ssize_t st;
-   char buf[16384];
-
-   /* can't use fread() */
-   do
-      st = read(sh->fd_in, buf, 16384);
-   while (st < 0 && errno == EINTR);
-
-   if (st == -1)
-      perror("[sock_handler_read]");
-
-   return (st > 0) ? dStrndup(buf, (uint_t)st) : NULL;
-}
-
-/*
- * Close this socket for reading and writing.
- */
-void sock_handler_close(SockHandler *sh)
-{
-   /* flush before closing */
-   sock_handler_write(sh, 1, "", 0);
-
-   fclose(sh->out);
-   close(sh->fd_out);
-}
-
-/*
- * Free the SockHandler structure
- */
-void sock_handler_free(SockHandler *sh)
-{
-   dFree(sh->buf);
-   dFree(sh);
-}
-
-/* ------------------------------------------------------------------------ */
-
--- a/dpi/dpiutil.h	Sun Nov 01 16:31:59 2009 -0300
+++ b/dpi/dpiutil.h	Sun Nov 01 16:31:59 2009 -0300
@@ -28,43 +28,6 @@
 #endif /* __cplusplus */
 
 
-#define BUFLEN 256
-#define TOUT 300
-
-
-/* Streamed Sockets API (not mandatory)  ----------------------------------*/
-
-typedef struct _SockHandler SockHandler;
-struct _SockHandler {
-   int fd_in;
-   int fd_out;
-   /* FILE *in;    --Unused. The stream functions block when reading. */
-   FILE *out;
-
-   char *buf;     /* internal buffer */
-   uint_t buf_sz;   /* data size */
-   uint_t buf_max;  /* allocated size */
-   uint_t flush_sz; /* max size before flush */
-};
-
-SockHandler *sock_handler_new(int fd_in, int fd_out, int flush_sz);
-int sock_handler_write(SockHandler *sh, int flush,
-                       const char *Data,size_t DataSize);
-int sock_handler_write_str(SockHandler *sh, int flush, const char *str);
-char *sock_handler_read(SockHandler *sh);
-void sock_handler_close(SockHandler *sh);
-void sock_handler_free(SockHandler *sh);
-
-#define sock_handler_printf(sh, flush, ...)                 \
-   D_STMT_START {                                           \
-      Dstr *dstr = dStr_sized_new(128);                     \
-      dStr_sprintf(dstr, __VA_ARGS__);                      \
-      sock_handler_write(sh, flush, dstr->str, dstr->len);  \
-      dStr_free(dstr, 1);                                   \
-   } D_STMT_END
-
-/* ----------------------------------------------------------------------- */
-
 /*
  * Escape URI characters in 'esc_set' as %XX sequences.
  * Return value: New escaped string.