]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/bio/bss_fd.c
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
15 #if defined(OPENSSL_NO_POSIX_IO)
17 * Dummy placeholder for BIO_s_fd...
19 BIO
*BIO_new_fd(int fd
, int close_flag
)
24 int BIO_fd_non_fatal_error(int err
)
29 int BIO_fd_should_retry(int i
)
34 const BIO_METHOD
*BIO_s_fd(void)
40 * As for unconditional usage of "UPLINK" interface in this module.
41 * Trouble is that unlike Unix file descriptors [which are indexes
42 * in kernel-side per-process table], corresponding descriptors on
43 * platforms which require "UPLINK" interface seem to be indexes
44 * in a user-land, non-global table. Well, in fact they are indexes
45 * in stdio _iob[], and recall that _iob[] was the very reason why
46 * "UPLINK" interface was introduced in first place. But one way on
47 * another. Neither libcrypto or libssl use this BIO meaning that
48 * file descriptors can only be provided by application. Therefore
49 * "UPLINK" calls are due...
51 static int fd_write(BIO
*h
, const char *buf
, int num
);
52 static int fd_read(BIO
*h
, char *buf
, int size
);
53 static int fd_puts(BIO
*h
, const char *str
);
54 static int fd_gets(BIO
*h
, char *buf
, int size
);
55 static long fd_ctrl(BIO
*h
, int cmd
, long arg1
, void *arg2
);
56 static int fd_new(BIO
*h
);
57 static int fd_free(BIO
*data
);
58 int BIO_fd_should_retry(int s
);
60 static const BIO_METHOD methods_fdp
= {
63 /* TODO: Convert to new style write function */
66 /* TODO: Convert to new style read function */
77 const BIO_METHOD
*BIO_s_fd(void)
82 BIO
*BIO_new_fd(int fd
, int close_flag
)
85 ret
= BIO_new(BIO_s_fd());
88 BIO_set_fd(ret
, fd
, close_flag
);
92 static int fd_new(BIO
*bi
)
97 bi
->flags
= BIO_FLAGS_UPLINK
; /* essentially redundant */
101 static int fd_free(BIO
*a
)
110 a
->flags
= BIO_FLAGS_UPLINK
;
115 static int fd_read(BIO
*b
, char *out
, int outl
)
121 ret
= UP_read(b
->num
, out
, outl
);
122 BIO_clear_retry_flags(b
);
124 if (BIO_fd_should_retry(ret
))
125 BIO_set_retry_read(b
);
131 static int fd_write(BIO
*b
, const char *in
, int inl
)
135 ret
= UP_write(b
->num
, in
, inl
);
136 BIO_clear_retry_flags(b
);
138 if (BIO_fd_should_retry(ret
))
139 BIO_set_retry_write(b
);
144 static long fd_ctrl(BIO
*b
, int cmd
, long num
, void *ptr
)
153 case BIO_C_FILE_SEEK
:
154 ret
= (long)UP_lseek(b
->num
, num
, 0);
156 case BIO_C_FILE_TELL
:
158 ret
= (long)UP_lseek(b
->num
, 0, 1);
162 b
->num
= *((int *)ptr
);
163 b
->shutdown
= (int)num
;
175 case BIO_CTRL_GET_CLOSE
:
178 case BIO_CTRL_SET_CLOSE
:
179 b
->shutdown
= (int)num
;
181 case BIO_CTRL_PENDING
:
182 case BIO_CTRL_WPENDING
:
196 static int fd_puts(BIO
*bp
, const char *str
)
201 ret
= fd_write(bp
, str
, n
);
205 static int fd_gets(BIO
*bp
, char *buf
, int size
)
209 char *end
= buf
+ size
- 1;
211 while (ptr
< end
&& fd_read(bp
, ptr
, 1) > 0) {
223 int BIO_fd_should_retry(int i
)
227 if ((i
== 0) || (i
== -1)) {
228 err
= get_last_sys_error();
230 return BIO_fd_non_fatal_error(err
);
235 int BIO_fd_non_fatal_error(int err
)
240 # ifdef WSAEWOULDBLOCK
241 # if WSAEWOULDBLOCK != EWOULDBLOCK
249 # if defined(ENOTCONN)
258 # if EWOULDBLOCK != EAGAIN