Change #include filenames from <foo.h> to <openssl.h>.
[openssl.git] / crypto / bio / bss_sock.c
index ac96027051ecdcff3a659497b38ba3be7af673b2..89b1dcab3746652601b4ac8146718a670a3af41a 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/bio/bss_sock.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
@@ -62,7 +62,7 @@
 #include <errno.h>
 #define USE_SOCKETS
 #include "cryptlib.h"
-#include "bio.h"
+#include <openssl/bio.h>
 
 #ifndef BIO_FD
 #ifndef NOPROTO
@@ -107,7 +107,8 @@ int BIO_fd_should_retry();
 #ifndef BIO_FD
 static BIO_METHOD methods_sockp=
        {
-       BIO_TYPE_SOCKET,"socket",
+       BIO_TYPE_SOCKET,
+       "socket",
        sock_write,
        sock_read,
        sock_puts,
@@ -117,7 +118,7 @@ static BIO_METHOD methods_sockp=
        sock_free,
        };
 
-BIO_METHOD *BIO_s_socket()
+BIO_METHOD *BIO_s_socket(void)
        {
        return(&methods_sockp);
        }
@@ -134,19 +135,17 @@ static BIO_METHOD methods_fdp=
        fd_free,
        };
 
-BIO_METHOD *BIO_s_fd()
+BIO_METHOD *BIO_s_fd(void)
        {
        return(&methods_fdp);
        }
 #endif
 
 #ifndef BIO_FD
-BIO *BIO_new_socket(fd,close_flag)
+BIO *BIO_new_socket(int fd, int close_flag)
 #else
-BIO *BIO_new_fd(fd,close_flag)
+BIO *BIO_new_fd(int fd,int close_flag)
 #endif
-int fd;
-int close_flag;
        {
        BIO *ret;
 
@@ -161,11 +160,10 @@ int close_flag;
        }
 
 #ifndef BIO_FD
-static int sock_new(bi)
+static int sock_new(BIO *bi)
 #else
-static int fd_new(bi)
+static int fd_new(BIO *bi)
 #endif
-BIO *bi;
        {
        bi->init=0;
        bi->num=0;
@@ -175,11 +173,10 @@ BIO *bi;
        }
 
 #ifndef BIO_FD
-static int sock_free(a)
+static int sock_free(BIO *a)
 #else
-static int fd_free(a)
+static int fd_free(BIO *a)
 #endif
-BIO *a;
        {
        if (a == NULL) return(0);
        if (a->shutdown)
@@ -188,11 +185,7 @@ BIO *a;
                        {
 #ifndef BIO_FD
                        shutdown(a->num,2);
-# ifdef WINDOWS
                        closesocket(a->num);
-# else
-                       close(a->num);
-# endif
 #else                  /* BIO_FD */
                        close(a->num);
 #endif
@@ -205,22 +198,20 @@ BIO *a;
        }
        
 #ifndef BIO_FD
-static int sock_read(b,out,outl)
+static int sock_read(BIO *b, char *out, int outl)
 #else
-static int fd_read(b,out,outl)
+static int fd_read(BIO *b, char *out,int outl)
 #endif
-BIO *b;
-char *out;
-int outl;
        {
        int ret=0;
 
        if (out != NULL)
                {
-               errno=0;
-#if defined(WINDOWS) && !defined(BIO_FD)
-               ret=recv(b->num,out,outl,0);
+#ifndef BIO_FD
+               clear_socket_error();
+               ret=readsocket(b->num,out,outl);
 #else
+               clear_sys_error();
                ret=read(b->num,out,outl);
 #endif
                BIO_clear_retry_flags(b);
@@ -238,20 +229,18 @@ int outl;
        }
 
 #ifndef BIO_FD
-static int sock_write(b,in,inl)
+static int sock_write(BIO *b, char *in, int inl)
 #else
-static int fd_write(b,in,inl)
+static int fd_write(BIO *b, char *in, int inl)
 #endif
-BIO *b;
-char *in;
-int inl;
        {
        int ret;
        
-       errno=0;
-#if defined(WINDOWS) && !defined(BIO_FD)
-       ret=send(b->num,in,inl,0);
+#ifndef BIO_FD
+       clear_socket_error();
+       ret=writesocket(b->num,in,inl);
 #else
+       clear_sys_error();
        ret=write(b->num,in,inl);
 #endif
        BIO_clear_retry_flags(b);
@@ -268,14 +257,10 @@ int inl;
        }
 
 #ifndef BIO_FD
-static long sock_ctrl(b,cmd,num,ptr)
+static long sock_ctrl(BIO *b, int cmd, long num, char *ptr)
 #else
-static long fd_ctrl(b,cmd,num,ptr)
+static long fd_ctrl(BIO *b, int cmd, long num, char *ptr)
 #endif
-BIO *b;
-int cmd;
-long num;
-char *ptr;
        {
        long ret=1;
        int *ip;
@@ -283,14 +268,21 @@ char *ptr;
        switch (cmd)
                {
        case BIO_CTRL_RESET:
+               num=0;
+       case BIO_C_FILE_SEEK:
 #ifdef BIO_FD
-               ret=(long)lseek(b->num,0,0);
+               ret=(long)lseek(b->num,num,0);
 #else
                ret=0;
 #endif
                break;
+       case BIO_C_FILE_TELL:
        case BIO_CTRL_INFO:
+#ifdef BIO_FD
+               ret=(long)lseek(b->num,0,1);
+#else
                ret=0;
+#endif
                break;
        case BIO_C_SET_FD:
 #ifndef BIO_FD
@@ -326,7 +318,6 @@ char *ptr;
        case BIO_CTRL_FLUSH:
                ret=1;
                break;
-               break;
        default:
                ret=0;
                break;
@@ -335,22 +326,17 @@ char *ptr;
        }
 
 #ifdef undef
-static int sock_gets(bp,buf,size)
-BIO *bp;
-char *buf;
-int size;
+static int sock_gets(BIO *bp, char *buf,int size)
        {
        return(-1);
        }
 #endif
 
 #ifndef BIO_FD
-static int sock_puts(bp,str)
+static int sock_puts(BIO *bp, char *str)
 #else
-static int fd_puts(bp,str)
+static int fd_puts(BIO *bp, char *str)
 #endif
-BIO *bp;
-char *str;
        {
        int n,ret;
 
@@ -364,37 +350,40 @@ char *str;
        }
 
 #ifndef BIO_FD
-int BIO_sock_should_retry(i)
+int BIO_sock_should_retry(int i)
 #else
-int BIO_fd_should_retry(i)
+int BIO_fd_should_retry(int i)
 #endif
-int i;
        {
+       int err;
+
        if ((i == 0) || (i == -1))
                {
-#if !defined(BIO_FD) && defined(WINDOWS)
-               errno=WSAGetLastError();
+#ifndef BIO_FD
+               err=get_last_socket_error();
+#else
+               err=get_last_sys_error();
 #endif
 
-#if defined(WINDOWS) /* more microsoft stupidity */
-               if ((i == -1) && (errno == 0))
+#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
+               if ((i == -1) && (err == 0))
                        return(1);
 #endif
+
 #ifndef BIO_FD
-               return(BIO_sock_non_fatal_error(errno));
+               return(BIO_sock_non_fatal_error(err));
 #else
-               return(BIO_fd_non_fatal_error(errno));
+               return(BIO_fd_non_fatal_error(err));
 #endif
                }
        return(0);
        }
 
 #ifndef BIO_FD
-int BIO_sock_non_fatal_error(err)
+int BIO_sock_non_fatal_error(int err)
 #else
-int BIO_fd_non_fatal_error(err)
+int BIO_fd_non_fatal_error(int err)
 #endif
-int err;
        {
        switch (err)
                {
@@ -403,8 +392,10 @@ int err;
        case WSAEWOULDBLOCK:
 # endif
 
-# if defined(WSAENOTCONN)
+# if 0 /* This appears to always be an error */
+#  if defined(WSAENOTCONN)
        case WSAENOTCONN:
+#  endif
 # endif
 #endif
 
@@ -418,6 +409,10 @@ int err;
 # endif
 #endif
 
+#if defined(ENOTCONN)
+       case ENOTCONN:
+#endif
+
 #ifdef EINTR
        case EINTR:
 #endif
@@ -440,7 +435,7 @@ int err;
        case EALREADY:
 #endif
                return(1);
-               break;
+               /* break; */
        default:
                break;
                }