src/sock.h
author Tero Marttila <terom@fixme.fi>
Sun, 19 Apr 2009 04:52:12 +0300
changeset 142 dc2bb09d412c
parent 140 aa390e52eda8
child 154 f4472119de3b
permissions -rw-r--r--
implement table-as-argument for lua_arg_*
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
117
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
     8
 *
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
     9
 * XXX: not just sockets anymore
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
 */
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    11
#include "error.h"
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
#include <sys/types.h>
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    13
#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
    14
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    15
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    16
 * 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
    17
 */
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
struct sock_stream;
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    20
/**
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    21
 * Callback for connect_async completion notification. If err is NULL, the connection completed succesfully,
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    22
 * otherwise, it failed.
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    23
 */
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    24
typedef void (*sock_stream_connect_cb) (struct sock_stream *sock, struct error_info *err, void *arg);
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    25
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    26
/**
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    27
 * Async callbacks for socket operation
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    28
 */
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    29
struct sock_stream_callbacks {
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    30
    /** Socket is readable */
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    31
    void (*on_read) (struct sock_stream *sock, void *arg);
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    32
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    33
    /** Socket is writeable */
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    34
    void (*on_write) (struct sock_stream *sock, void *arg);
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    35
};
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    36
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    37
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    38
 * Socket function error codes
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    39
 */
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
    40
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
    41
    _ERR_SOCK_BEGIN = _ERR_SOCK,
117
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    42
    ERR_SOCKET,         ///< socket(2) failed
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    43
    ERR_CONNECT,        ///< connect(2) error - either direct or async
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    44
    ERR_READ,           ///< read(2) error - will probably show up as an ERR_WRITE as well
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    45
    ERR_READ_EOF,       ///< EOF on read(2)
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    46
    ERR_WRITE,          ///< write(2) error - data was unsent, will probably show up as an ERR_READ as well
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    47
    ERR_WRITE_EOF,      ///< write(2) gave EOF - zero bytes written
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    48
    ERR_FCNTL,          ///< fcntl(2) failed
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    49
    ERR_CLOSE,          ///< close(2) failed, some written data was probably not sent
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    50
    ERR_GETSOCKOPT,     ///< getsockopt(2) failed
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    51
    ERR_OPEN,           ///< open(2) failed
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
    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
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    54
/**
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    55
 * 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
    56
 *
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    57
 * 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
    58
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    59
 * @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
    60
 * @param err returned error info
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    61
 */
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    62
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
    63
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    64
/**
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    65
 * A simple TCP connect to the given host/service, using getaddrinfo. The connected socket is returned via *sock_ptr. 
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    66
 * 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
    67
 *
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    68
 * @param sock_ptr the new sock_stream
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    69
 * @param host the hostname to connect to
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    70
 * @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
    71
 * @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
    72
 */
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    73
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
    74
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    75
/**
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    76
 * Start a non-blocking TCP connect to the given host/service. The socket will not yet be connected once the function
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    77
 * returns, but rather, the readyness of the socket will be indicated later using the given \a cb_func.
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    78
 *
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    79
 * Note that currently it is an error to call sock_stream_event_init before the cb_func has been called.
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    80
 *
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    81
 * XXX: blocking DNS resolution
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    82
 *
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    83
 * @param sock_ptr the new sock_stream
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    84
 * @param host the hostname to connect to
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    85
 * @param service the service name (i.e. port) to connect to
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    86
 * @param cb_func the callback used to handle the result of the async operation
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    87
 * @param cb_arg opaque context argument passed back to cb_func
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    88
 * @param err returned error info
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    89
 */
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    90
err_t sock_tcp_connect_async (struct sock_stream **sock_ptr, const char *host, const char *service, 
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    91
        sock_stream_connect_cb cb_func, void *cb_arg, struct error_info *err);
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    92
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    93
/**
117
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    94
 * A read-only "socket" based on a FIFO, this provides nonblocking read operations by re-opening the FIFO on EOF.
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    95
 */
118
05b8d5150313 implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents: 117
diff changeset
    96
err_t fifo_open_read (struct sock_stream **stream_ptr, const char *path, struct error_info *err);
117
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    97
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    98
/**
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    99
 * 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
   100
 * 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
   101
 * 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
   102
 * 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
   103
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   104
 * 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
   105
 * sock_stream_error()..
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   106
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   107
 * @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
   108
 * @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
   109
 * @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
   110
 * @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
   111
 */
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
   112
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
   113
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   114
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   115
 * 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
   116
 * 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
   117
 * 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
   118
 * 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
   119
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   120
 * 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
   121
 * sock_stream_error().
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   122
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   123
 * @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
   124
 * @param buf the byte buffer
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   125
 * @param len number of bytes to write
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   126
 * @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
   127
 */
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
   128
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
   129
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   130
/**
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
   131
 * 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
   132
 * 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
   133
 *
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
   134
 * 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
   135
 *
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   136
 * @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
   137
 * @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
   138
 * @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
   139
 */
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
   140
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
   141
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   142
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   143
 * 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
   144
 *
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
   145
 * 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
   146
 * 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
   147
 * 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
   148
 * 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
   149
 */
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
   150
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
   151
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
   152
/**
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
   153
 * Get current error_info for \a sock.
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
   154
 */
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
   155
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
   156
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
   157
/**
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
 * 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
   159
 *
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
 * 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
   161
 */
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
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
   163
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   164
#endif