vttp
An HTTP backed Virtual Table extension for SQLite
Loading...
Searching...
No Matches
Macros | Functions
tcp.h File Reference

socket API More...

#include <netdb.h>
#include <openssl/ssl.h>
#include <openssl/types.h>
#include <stdbool.h>
Include dependency graph for tcp.h:

Go to the source code of this file.

Macros

#define MAX_HOSTNAME_LENGTH   255
 

Functions

int tcp_getaddrinfo (const char *hostname, const char *port, struct addrinfo **addr)
 Write address info from HOSTNAME and PORT into ADDR.
 
int tcp_socket (struct addrinfo *addrinfo)
 Open socket fd from ADDRINFO and return it.
 
int tcp_connect (int fd, struct sockaddr *addr, socklen_t len, SSL **ssl, SSL_CTX **ctx, const char *hostname)
 connect() to socket FD using ADDR, optionally using TLS if TLS is not NULL.
 
ssize_t tcp_send (int fd, const char *bytes, size_t len, SSL *ssl)
 Send LEN BYTES over tcp connection at FD, potentially writing over the TLS connection at SSL, if it exists.
 
ssize_t tcp_recv (int fd, char *bytes, size_t len, SSL *ssl)
 Maybe recv LEN BYTES over the TCP connection at SSL, if it exists.
 
void tcp_tls_free (SSL *ssl, SSL_CTX *ctx)
 Shutdown and free SSL and CTX.
 

Detailed Description

socket API

Function Documentation

◆ tcp_connect()

int tcp_connect ( int  fd,
struct sockaddr *  addr,
socklen_t  len,
SSL **  ssl,
SSL_CTX **  ctx,
const char *  hostname 
)

connect() to socket FD using ADDR, optionally using TLS if TLS is not NULL.

Return values
0OK
-1Error connecting to socket
-2Error with TLS connection

◆ tcp_getaddrinfo()

int tcp_getaddrinfo ( const char *  hostname,
const char *  port,
struct addrinfo **  addr 
)

Write address info from HOSTNAME and PORT into ADDR.

Return values
0OK. Address Info written to ADDR.
22EINVAL. At least one of HOSTNAME or PORT or ADDR is NULL.
ANYTHING_ELSEError. The return value of getaddrinfo() when non-zero.

◆ tcp_recv()

ssize_t tcp_recv ( int  fd,
char *  bytes,
size_t  len,
SSL *  ssl 
)

Maybe recv LEN BYTES over the TCP connection at SSL, if it exists.

If SSL is NULL then tcp_recv() fallsback to plain recv() call to SOCKFD.

Return values
-1ERROR - Neither the SOCKFD or SSL sockets can be written to.
(x>= 0) OK - X bytes written out.

◆ tcp_send()

ssize_t tcp_send ( int  fd,
const char *  bytes,
size_t  len,
SSL *  ssl 
)

Send LEN BYTES over tcp connection at FD, potentially writing over the TLS connection at SSL, if it exists.

If SSL is NULL, then tcp_send() fallsback to plain send() call to SOCKFD.

Return values
-1ERROR - Neither the SOCKFD or SSL sockets can be written to.
x>=0OK - x bytes written out.

◆ tcp_socket()

int tcp_socket ( struct addrinfo *  addrinfo)

Open socket fd from ADDRINFO and return it.

Return values
-1Error opening socket.
NONNEGATIVEOK, a socket file descriptor.

◆ tcp_tls_free()

void tcp_tls_free ( SSL *  ssl,
SSL_CTX *  ctx 
)

Shutdown and free SSL and CTX.

If both SSL and CTX are NULL, then this is a no-op.