src/sock.h
author Tero Marttila <terom@fixme.fi>
Tue, 10 Mar 2009 19:52:38 +0200
changeset 34 763f65f9df0c
parent 30 7f8dd120933f
child 40 51678c7eae03
permissions -rw-r--r--
add doxygen.conf, and tweak comments
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef SOCK_H
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define SOCK_H
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     4
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     5
 * @file
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     6
 *
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 * Low-level socket-related functions
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
     9
#include "error.h"
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include <sys/types.h>
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    11
#include <event2/event.h>
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    13
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    14
 * The generic stream socket handle
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
 */
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
struct sock_stream;
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    18
/**
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    19
 * Async callbacks for socket operation
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    20
 */
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    21
struct sock_stream_callbacks {
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    22
    /** Sockeet is readable */
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    23
    void (*on_read)(struct sock_stream *sock, void *arg);
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    24
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    25
    /** Socket is writeable */
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    26
    void (*on_write)(struct sock_stream *sock, void *arg);
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    27
};
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    28
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    29
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    30
 * Socket function error codes
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    31
 */
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    32
enum sock_error_code {
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    33
    _ERR_SOCK_BEGIN = _ERR_SOCK,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    34
    
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    35
    /** socket() error */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    36
    ERR_SOCKET,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    37
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    38
    /** connect() error */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    39
    ERR_CONNECT,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    40
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    41
    /** read() error */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    42
    ERR_READ,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    43
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    44
    /** EOF on read() */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    45
    ERR_READ_EOF,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    46
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    47
    /** write() error */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    48
    ERR_WRITE,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    49
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    50
    /** EOF on write()  */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    51
    ERR_WRITE_EOF,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    52
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    53
    /** Error on fcntl() */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    54
    ERR_FCNTL,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    55
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    56
    /** Lingering error on close() */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    57
    ERR_CLOSE,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    58
};
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    59
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    60
/**
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    61
 * Initialize the socket module's global state. Call this before calling any other sock_* functions.
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    62
 *
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    63
 * The given \a ev_base is the libevent base to use for nonblocking operation.
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    64
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    65
 * @param ev_base the libevent base to use for events
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    66
 * @param err returned error info
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    67
 */
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    68
err_t sock_init (struct event_base *ev_base, struct error_info *err);
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    69
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    70
/**
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    71
 * A simple blocking TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
    72
 * *sock_ptr. In case of errors, additional error information is stored in *err.
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    73
 *
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    74
 * @param sock_ptr the new sock_stream
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    75
 * @param host the hostname to connect to
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    76
 * @param service the service name (i.e. port) to connect to
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    77
 * @param err returned error info
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
 *
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
 * XXX: blocking
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
 */
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    81
err_t sock_tcp_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err);
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    83
/*
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
    84
 * A simple blocking SSL connect to the given host/service. The connected/handshake'd SSL socket is returned via
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
    85
 * *sock_ptr. In case of errors, additional error information is stored in *err.
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
 *
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    87
 * @param sock_ptr the new sock_stream
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    88
 * @param host the hostname to connect to
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    89
 * @param service the TCP service name (i.e. port) to connect to
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    90
 * @param err returned error info
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    91
 *
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
 * XXX: blocking
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
 * XXX: doesn't do any certificate verification.
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
 */
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
    95
err_t sock_ssl_connect (struct sock_stream **sock_ptr, const char *host, const char *service, struct error_info *err);
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    97
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    98
 * Read a series of bytes from the socket into the given \a buf (up to \a len bytes). If succesfull, this returns
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    99
 * the number of bytes read (which will be less than or equal to \a len). If the socket is nonblocking (i.e.
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   100
 * sock_stream_event_init() was set), and there is no data available, this returns zero, and one should use
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   101
 * sock_stream_event_enable() to wait for more data.
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   102
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   103
 * On errors, this returns the negative err_t code, and the specific error information can be accessed using
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   104
 * sock_stream_error()..
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   105
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   106
 * @param sock the socket to read the bytes from
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   107
 * @param buf the byte buffer to write the bytes into
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   108
 * @param len the number of bytes to read into the buffer
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   109
 * @return bytes read, zero if none available, -err_t
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   110
 */
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   111
int sock_stream_read (struct sock_stream *sock, void *buf, size_t len);
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   112
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   113
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   114
 * Write a series of bytes from the given \a buf (containing \a len bytes) to the socket. If succesfull, this returns
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   115
 * the number of bytes written (which may be less than \a len if the OS write buffer was full). If the socket is
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   116
 * nonblocking (i.e. sock_stream_event_init() was set), and the operation would have blocked, no data was written, and
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   117
 * this returns zero, and one should use sock_stream_event_enable() to retry.
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   118
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   119
 * On errors, this returns the negative err_t code, and the specific error information can be accessed using
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   120
 * sock_stream_error().
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   121
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   122
 * @param sock the socket to write the bytes to
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   123
 * @param buf the byte buffer
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   124
 * @param len number of bytes to write
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   125
 * @return bytes written, zero if would have blocked, -err_t
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   126
 */
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   127
int sock_stream_write (struct sock_stream *sock, const void *buf, size_t len);
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   128
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   129
/**
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   130
 * Initialize event-based operation for this sock_stream. This will set the stream into nonblocking mode, and the given
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   131
 * callbacks will be fired once enabled using sock_stream_event_enable().
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   132
 *
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   133
 * Note that the callbacks struct isn't copied - it's used as-is-given.
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   134
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   135
 * @param sock the socket to set up for nonblocking operation
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   136
 * @param callbacks the on_read/on_write callbacks to invoke
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   137
 * @param arg the context argument for the callbacks
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
 */
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   139
err_t sock_stream_event_init (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg);
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   140
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   141
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   142
 * Enable some events for this sock, as set up earlier with event_init. Mask should contain EV_READ/EV_WRITE.
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   143
 *
12
4147fae232d9 update sock_stream_read/write semantics for EOF/EAGAIN, tentative event-based gnutls code
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   144
 * The implementation of this is slightly hazy for complex protocols; this should only be used to map from
4147fae232d9 update sock_stream_read/write semantics for EOF/EAGAIN, tentative event-based gnutls code
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   145
 * sock_stream_read/write to the corresponding sock_stream_callback. That is, if sock_stream_read returns zero, then
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   146
 * call event_enable(EV_READ), wherepon on_read will later be called. Other operations (such as calling
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   147
 * sock_stream_write with *different* data after it once returns zero) might result in errors.
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   148
 */
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
   149
err_t sock_stream_event_enable (struct sock_stream *sock, short mask);
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
   150
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
   151
/**
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
   152
 * Get current error_info for \a sock.
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
   153
 */
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
   154
const struct error_info* sock_stream_error (struct sock_stream *sock);
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   155
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   156
/**
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   157
 * Close and release the given socket, ignoring errors. It must not be used anymore after this.
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   158
 *
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   159
 * This is intended to be used to abort in case of errors, and does not close the connection cleanly.
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   160
 */
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   161
void sock_stream_release (struct sock_stream *sock);
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   162
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
#endif