X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcsockconn.h;h=9b190d1bb157cdf20bf4a4e6711546ebd647c19b;hb=6175840fb524397cecae2d70b4befa8d377a652d;hp=291a5a46e798546d964f12d42421446cc8bb98e5;hpb=439d7874f4cc9590a4a4e5d57f924c1b661a1485;p=silc.git diff --git a/lib/silccore/silcsockconn.h b/lib/silccore/silcsockconn.h index 291a5a46..9b190d1b 100644 --- a/lib/silccore/silcsockconn.h +++ b/lib/silccore/silcsockconn.h @@ -21,6 +21,10 @@ #ifndef SILCSOCKCONN_H #define SILCSOCKCONN_H +/* Forward declarations */ +typedef struct SilcSocketConnectionStruct *SilcSocketConnection; +typedef struct SilcSocketConnectionHB *SilcSocketConnectionHB; + /* Socket types. These identifies the socket connection. */ typedef enum { SILC_SOCKET_TYPE_UNKNOWN = 0, @@ -36,6 +40,12 @@ typedef enum { #define SILC_SF_DISCONNECTING 3 #define SILC_SF_DISCONNECTED 4 +/* Heartbeat callback function. This is the function in the application + that this library will call when it is time to send the keepalive + packet SILC_PACKET_HEARTBEAT. */ +typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, + void *context); + /* SILC Socket Connection object. @@ -91,8 +101,12 @@ typedef enum { inbuf buffer and outgoing data after encryption is put to the outbuf buffer. + SilcSocketConnectionHB hb + + The heartbeat context. If NULL, heartbeat is not performed. + */ -typedef struct { +struct SilcSocketConnectionStruct { int sock; SilcSocketType type; void *user_data; @@ -105,9 +119,19 @@ typedef struct { SilcBuffer inbuf; SilcBuffer outbuf; -} SilcSocketConnectionObject; -typedef SilcSocketConnectionObject *SilcSocketConnection; + SilcSocketConnectionHB hb; +}; + +/* Heartbeat context */ +struct SilcSocketConnectionHB { + unsigned long heartbeat; + SilcSocketConnectionHBCb hb_callback; + void *hb_context; + void *timeout_queue; + SilcTask hb_task; + SilcSocketConnection sock; +}; /* Macros */ @@ -136,5 +160,10 @@ typedef SilcSocketConnectionObject *SilcSocketConnection; void silc_socket_alloc(int sock, SilcSocketType type, void *user_data, SilcSocketConnection *new_socket); void silc_socket_free(SilcSocketConnection sock); +void silc_socket_set_heartbeat(SilcSocketConnection sock, + unsigned long heartbeat, + void *hb_context, + SilcSocketConnectionHBCb hb_callback, + void *timeout_queue); #endif