terom@1: #ifndef SOCK_INTERNAL_H terom@1: #define SOCK_INTERNAL_H terom@1: terom@1: #include "sock.h" terom@1: terom@1: /* terom@9: * Global config related to all sock_streams terom@9: */ terom@9: extern struct sock_stream_ctx { terom@9: /* Event core */ terom@9: struct event_base *ev_base; terom@9: terom@9: } _sock_stream_ctx; terom@9: terom@9: /* terom@1: * The base type struct, which defines the method table. terom@1: */ terom@1: struct sock_stream_type { terom@1: /* method table */ terom@1: struct sock_stream_methods { terom@1: /* Normal read(2) */ terom@10: err_t (*read) (struct sock_stream *sock, void *buf, size_t *len); terom@1: terom@1: /* Normal write(2) */ terom@10: err_t (*write) (struct sock_stream *sock, const void *buf, size_t *len); terom@10: terom@10: /* Initialize events. cb_info/cb_arg are already updated */ terom@10: err_t (*event_init) (struct sock_stream *sock); terom@10: terom@10: /* Enable events as specified */ terom@10: err_t (*event_enable) (struct sock_stream *sock, short mask); terom@1: terom@1: } methods; terom@1: }; terom@1: terom@1: /* terom@1: * The base sock_stream type, as used by the sock_stream_* functions. terom@1: * terom@1: * The specific implementations should embed this at the start of their type-specific struct, and then cast around terom@1: * as appropriate. terom@1: */ terom@1: struct sock_stream { terom@3: /* The sock_stream_type for this socket */ terom@1: struct sock_stream_type *type; terom@3: terom@3: /* Last error info */ terom@3: struct error_info err; terom@9: terom@9: /* Callbacks */ terom@9: const struct sock_stream_callbacks *cb_info; terom@9: terom@9: /* Callback arg */ terom@9: void *cb_arg; terom@1: }; terom@1: terom@1: #define SOCK_FROM_BASE(sock, type) ((type*) sock) terom@4: #define SOCK_ERR(sock) (&(sock)->err) terom@3: terom@3: /* terom@3: * Initialize a sock_stream with the given sock_stream_type. terom@3: * terom@3: * The sock_stream should be initialized to zero. It is a bug to call this twice. terom@3: */ terom@3: void sock_stream_init (struct sock_stream *sock, struct sock_stream_type *type); terom@1: terom@12: /* terom@12: * Invoke the appropriate callbacks for the given EV_* bitmask. terom@12: */ terom@12: void sock_stream_invoke_callbacks (struct sock_stream *sock, short what); terom@12: terom@1: #endif /* SOCK_INTERNAL_H */