-#else /* BIO_FD */
- close(a->num);
-#endif
-
- }
- a->init=0;
- a->flags=0;
- }
- return(1);
- }
-
-#ifndef BIO_FD
-static int sock_read(b,out,outl)
-#else
-static int fd_read(b,out,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);
-#else
- ret=read(b->num,out,outl);
-#endif
- BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
-#ifndef BIO_FD
- if (BIO_sock_should_retry(ret))
-#else
- if (BIO_fd_should_retry(ret))
-#endif
- BIO_set_retry_read(b);
- }
- }
- return(ret);
- }
-
-#ifndef BIO_FD
-static int sock_write(b,in,inl)
-#else
-static int fd_write(b,in,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);
-#else
- ret=write(b->num,in,inl);
-#endif
- BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
-#ifndef BIO_FD
- if (BIO_sock_should_retry(ret))
-#else
- if (BIO_fd_should_retry(ret))
-#endif
- BIO_set_retry_write(b);
- }
- return(ret);
- }
-
-#ifndef BIO_FD
-static long sock_ctrl(b,cmd,num,ptr)
-#else
-static long fd_ctrl(b,cmd,num,ptr)
-#endif
-BIO *b;
-int cmd;
-long num;
-char *ptr;
- {
- long ret=1;
- int *ip;
-
- switch (cmd)
- {
- case BIO_CTRL_RESET:
-#ifdef BIO_FD
- ret=(long)lseek(b->num,0,0);
-#else
- ret=0;
-#endif
- break;
- case BIO_CTRL_INFO:
- ret=0;
- break;
- case BIO_C_SET_FD:
-#ifndef BIO_FD
- sock_free(b);
-#else
- fd_free(b);
-#endif
- b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
- break;
- case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
- break;
- case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
- break;
- case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
- break;
- case BIO_CTRL_PENDING:
- case BIO_CTRL_WPENDING:
- ret=0;
- break;
- case BIO_CTRL_DUP:
- case BIO_CTRL_FLUSH:
- ret=1;
- break;
- break;
- default:
- ret=0;
- break;
- }
- return(ret);
- }
-
-#ifdef undef
-static int sock_gets(bp,buf,size)
-BIO *bp;
-char *buf;
-int size;
- {
- return(-1);
- }
-#endif
-
-#ifndef BIO_FD
-static int sock_puts(bp,str)
-#else
-static int fd_puts(bp,str)
-#endif
-BIO *bp;
-char *str;
- {
- int n,ret;
-
- n=strlen(str);
-#ifndef BIO_FD
- ret=sock_write(bp,str,n);
-#else
- ret=fd_write(bp,str,n);
-#endif
- return(ret);
- }
-
-#ifndef BIO_FD
-int BIO_sock_should_retry(i)
-#else
-int BIO_fd_should_retry(i)
-#endif
-int i;
- {
- if ((i == 0) || (i == -1))
- {
-#if !defined(BIO_FD) && defined(WINDOWS)
- errno=WSAGetLastError();
-#endif
-
-#if defined(WINDOWS) /* more microsoft stupidity */
- if ((i == -1) && (errno == 0))
- return(1);
-#endif
-#ifndef BIO_FD
- return(BIO_sock_non_fatal_error(errno));
-#else
- return(BIO_fd_non_fatal_error(errno));
-#endif
- }
- return(0);
- }
-
-#ifndef BIO_FD
-int BIO_sock_non_fatal_error(err)
-#else
-int BIO_fd_non_fatal_error(err)
-#endif
-int err;
- {
- switch (err)
- {
-#if !defined(BIO_FD) && defined(WINDOWS)
-# if defined(WSAEWOULDBLOCK)
- case WSAEWOULDBLOCK: