src/sock.h
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 08:21:22 +0200
changeset 8 be88e543c8ff
parent 5 a09a0797f6f0
child 9 4c4c906cc649
permissions -rw-r--r--
split off line_proto, and make sock_stream_error return a const error_info
#ifndef SOCK_H
#define SOCK_H

/*
 * Low-level socket-related functions
 */
#include "error.h"
#include <sys/types.h>

/*
 * The generic socket handle
 */
struct sock_stream;

/*
 * Initialize the socket module's global state. Call this before calling any other sock_* functions.
 */
err_t sock_init (struct error_info *err);

/*
 * A simple blocking TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via
 * *sock_ptr. In case of errors, additional error information is stored in *err.
 *
 * @return zero on success, nonzero on error
 *
 * XXX: blocking
 */
err_t sock_tcp_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err);

/*
 * A simple blocking SSL connect to the given host/service. The connected/handshake'd SSL socket is returned via
 * *sock_ptr. In case of errors, additional error information is stored in *err.
 *
 * XXX: blocking
 * XXX: doesn't do any certificate verification.
 */
err_t sock_gnutls_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err);

/*
 * The generic read/write API for stream sockets.
 */
err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len);
err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len);

/**
 * Get current error_info for \a sock.
 */
const struct error_info* sock_stream_error (struct sock_stream *sock);

#endif