open62541 1.3.12
Open source implementation of OPC UA
Loading...
Searching...
No Matches
bio_sockets.h
Go to the documentation of this file.
1#if !defined(__BIO_SOCKET_TEMPLATE_H__)
2#define __BIO_SOCKET_TEMPLATE_H__
3
4#include <openssl/bio.h>
5#include <openssl/ssl.h>
6#include <openssl/err.h>
7
8/*
9 A template for opening a non-blocking BIO socket.
10*/
11BIO* open_nb_socket(const char* addr, const char* port) {
12 BIO* bio = BIO_new_connect(addr);
13 BIO_set_nbio(bio, 1);
14 BIO_set_conn_port(bio, port);
15
16 /* timeout after 10 seconds */
17 int start_time = time(NULL);
18 while(BIO_do_connect(bio) == 0 && (int)time(NULL) - start_time < 10);
19
20 if (BIO_do_connect(bio) <= 0) {
21 fprintf(stderr, "Failed to open socket: BIO_do_connect returned <= 0\n");
22 return NULL;
23 }
24
25 return bio;
26}
27
28#endif
BIO * open_nb_socket(const char *addr, const char *port)
Definition bio_sockets.h:11