Commit be0d17e8 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

cleaned up Curl_write() and the sub functions it uses for various protocols.

They all now return ssize_t to Curl_write().

Unfortunately, Curl_read() is in a sorrier state but it too would benefit from
a similar cleanup.
parent 4eb35406
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -452,13 +452,12 @@ Curl_gtls_connect(struct connectdata *conn,




/* return number of sent (non-SSL) bytes */
/* return number of sent (non-SSL) bytes */
int Curl_gtls_send(struct connectdata *conn,
ssize_t Curl_gtls_send(struct connectdata *conn,
                   int sockindex,
                   int sockindex,
                   void *mem,
                   void *mem,
                   size_t len)
                   size_t len)
{
{
  int rc;
  ssize_t rc = gnutls_record_send(conn->ssl[sockindex].session, mem, len);
  rc = gnutls_record_send(conn->ssl[sockindex].session, mem, len);


  if(rc < 0 ) {
  if(rc < 0 ) {
    if(rc == GNUTLS_E_AGAIN)
    if(rc == GNUTLS_E_AGAIN)
+3 −3
Original line number Original line Diff line number Diff line
@@ -7,7 +7,7 @@
 *                            | (__| |_| |  _ <| |___
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *                             \___|\___/|_| \_\_____|
 *
 *
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 *
 * This software is licensed as described in the file COPYING, which
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * you should have received as part of this distribution. The terms
@@ -32,7 +32,7 @@ void Curl_gtls_close_all(struct SessionHandle *data);
void Curl_gtls_close(struct connectdata *conn); /* close a SSL connection */
void Curl_gtls_close(struct connectdata *conn); /* close a SSL connection */


/* return number of sent (non-SSL) bytes */
/* return number of sent (non-SSL) bytes */
int Curl_gtls_send(struct connectdata *conn, int sockindex,
ssize_t Curl_gtls_send(struct connectdata *conn, int sockindex,
                       void *mem, size_t len);
                       void *mem, size_t len);
ssize_t Curl_gtls_recv(struct connectdata *conn, /* connection data */
ssize_t Curl_gtls_recv(struct connectdata *conn, /* connection data */
                       int num,                  /* socketindex */
                       int num,                  /* socketindex */
+3 −2
Original line number Original line Diff line number Diff line
@@ -7,7 +7,7 @@
 *                            | (__| |_| |  _ <| |___
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *                             \___|\___/|_| \_\_____|
 *
 *
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 *
 * This software is licensed as described in the file COPYING, which
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * you should have received as part of this distribution. The terms
@@ -53,6 +53,7 @@ int Curl_sec_read_msg (struct connectdata *conn, char *, int);
int Curl_sec_vfprintf(struct connectdata *, FILE *, const char *, va_list);
int Curl_sec_vfprintf(struct connectdata *, FILE *, const char *, va_list);
int Curl_sec_fprintf2(struct connectdata *conn, FILE *f, const char *fmt, ...);
int Curl_sec_fprintf2(struct connectdata *conn, FILE *f, const char *fmt, ...);
int Curl_sec_vfprintf2(struct connectdata *conn, FILE *, const char *, va_list);
int Curl_sec_vfprintf2(struct connectdata *conn, FILE *, const char *, va_list);
ssize_t Curl_sec_send(struct connectdata *conn, int, char *, int);
int Curl_sec_write(struct connectdata *conn, int, char *, int);
int Curl_sec_write(struct connectdata *conn, int, char *, int);


void Curl_sec_end (struct connectdata *);
void Curl_sec_end (struct connectdata *);
+7 −0
Original line number Original line Diff line number Diff line
@@ -278,6 +278,13 @@ Curl_sec_write(struct connectdata *conn, int fd, char *buffer, int length)
  return tx;
  return tx;
}
}


ssize_t
Curl_sec_send(struct connectdata *conn, int num, char *buffer, int length)
{
  curl_socket_t fd = conn->sock[num];
  return (ssize_t)Curl_sec_write(conn, fd, buffer, length);
}

int
int
Curl_sec_putc(struct connectdata *conn, int c, FILE *F)
Curl_sec_putc(struct connectdata *conn, int c, FILE *F)
{
{
+42 −36
Original line number Original line Diff line number Diff line
@@ -53,7 +53,7 @@
#ifdef HAVE_KRB4
#ifdef HAVE_KRB4
#include "krb4.h"
#include "krb4.h"
#else
#else
#define Curl_sec_write(a,b,c,d) -1
#define Curl_sec_send(a,b,c,d) -1
#define Curl_sec_read(a,b,c,d) -1
#define Curl_sec_read(a,b,c,d) -1
#endif
#endif


@@ -313,35 +313,13 @@ CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn,
  return res;
  return res;
}
}


/*
static ssize_t Curl_plain_send(struct connectdata *conn,
 * Curl_write() is an internal write function that sends plain (binary) data
                               int num,
 * to the server. Works with plain sockets, SSL or kerberos.
 */
CURLcode Curl_write(struct connectdata *conn,
                    curl_socket_t sockfd,
                               void *mem,
                               void *mem,
                    size_t len,
                               size_t len)
                    ssize_t *written)
{
{
  ssize_t bytes_written;
  curl_socket_t sockfd = conn->sock[num];
  CURLcode retcode;
  ssize_t bytes_written = swrite(sockfd, mem, len);
  int num = (sockfd == conn->sock[SECONDARYSOCKET]);

  if (conn->ssl[num].use) {
    /* only TRUE if SSL enabled */
    bytes_written = Curl_ssl_send(conn, num, mem, len);
  }
#ifdef USE_LIBSSH2
  else if (conn->protocol & PROT_SCP) {
    bytes_written = Curl_scp_send(conn, num, mem, len);
  }
#endif /* !USE_LIBSSH2 */
  else {
    if(conn->sec_complete)
      /* only TRUE if krb4 enabled */
      bytes_written = Curl_sec_write(conn, sockfd, mem, len);
    else
      bytes_written = swrite(sockfd, mem, len);


  if(-1 == bytes_written) {
  if(-1 == bytes_written) {
    int err = Curl_sockerrno();
    int err = Curl_sockerrno();
@@ -351,10 +329,9 @@ CURLcode Curl_write(struct connectdata *conn,
      /* This is how Windows does it */
      /* This is how Windows does it */
      (WSAEWOULDBLOCK == err)
      (WSAEWOULDBLOCK == err)
#else
#else
        /* As pointed out by Christophe Demory on March 11 2003, errno
      /* errno may be EWOULDBLOCK or on some systems EAGAIN when it returned
           may be EWOULDBLOCK or on some systems EAGAIN when it returned
         due to its inability to send off data without blocking. We therefor
           due to its inability to send off data without blocking. We
         treat both error codes the same here */
           therefor treat both error codes the same here */
      (EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err)
      (EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err)
#endif
#endif
      )
      )
@@ -364,7 +341,36 @@ CURLcode Curl_write(struct connectdata *conn,
      failf(conn->data, "Send failure: %s",
      failf(conn->data, "Send failure: %s",
            Curl_strerror(conn, err));
            Curl_strerror(conn, err));
  }
  }
  return bytes_written;
}
}

/*
 * Curl_write() is an internal write function that sends data to the
 * server. Works with plain sockets, SCP, SSL or kerberos.
 */
CURLcode Curl_write(struct connectdata *conn,
                    curl_socket_t sockfd,
                    void *mem,
                    size_t len,
                    ssize_t *written)
{
  ssize_t bytes_written;
  CURLcode retcode;
  int num = (sockfd == conn->sock[SECONDARYSOCKET]);

  if (conn->ssl[num].use)
    /* only TRUE if SSL enabled */
    bytes_written = Curl_ssl_send(conn, num, mem, len);
#ifdef USE_LIBSSH2
  else if (conn->protocol & PROT_SCP)
    bytes_written = Curl_scp_send(conn, num, mem, len);
#endif /* !USE_LIBSSH2 */
  else if(conn->sec_complete)
    /* only TRUE if krb4 enabled */
    bytes_written = Curl_sec_send(conn, num, mem, len);
  else
    bytes_written = Curl_plain_send(conn, num, mem, len);

  *written = bytes_written;
  *written = bytes_written;
  retcode = (-1 != bytes_written)?CURLE_OK:CURLE_SEND_ERROR;
  retcode = (-1 != bytes_written)?CURLE_OK:CURLE_SEND_ERROR;


Loading