X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcsockconn.h;h=ea47d3da1e0b716847b88c90fdf404aea3e7a018;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=c265bfb86cb4e073e93e16fd4a7829b94775f402;hpb=377ac1cec4ace380054fd234babb6eefeab04a91;p=silc.git diff --git a/lib/silcutil/silcsockconn.h b/lib/silcutil/silcsockconn.h index c265bfb8..ea47d3da 100644 --- a/lib/silcutil/silcsockconn.h +++ b/lib/silcutil/silcsockconn.h @@ -1,24 +1,24 @@ -/****h* silcutil/silcsockconn.h - * - * NAME - * - * silcsockconn.h - * - * COPYRIGHT - * - * Author: Pekka Riikonen - * - * Copyright (C) 1997 - 2001 Pekka Riikonen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. +/* + + silcsockconn.h + + Author: Pekka Riikonen + + Copyright (C) 1997 - 2001 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +/****h* silcutil/SilcSocketConnectionAPI * * DESCRIPTION * @@ -65,7 +65,7 @@ typedef struct SilcSocketConnectionStruct *SilcSocketConnection; * interface routines. * ***/ -typedef struct SilcSocketConnectionHB *SilcSocketConnectionHB; +typedef struct SilcSocketConnectionHBStruct *SilcSocketConnectionHB; /****d* silcutil/SilcSocketConnectionAPI/SilcSocketType * @@ -93,28 +93,14 @@ typedef enum { /***/ /* Socket flags */ -#define SILC_SF_NONE 0 -#define SILC_SF_INBUF_PENDING 1 -#define SILC_SF_OUTBUF_PENDING 2 -#define SILC_SF_DISCONNECTING 3 -#define SILC_SF_DISCONNECTED 4 - -/****f* silcutil/SilcSocketConnectionAPI/SilcSocketConnectionHBCb - * - * SYNOPSIS - * - * typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, - * void *context); - * - * DESCRIPTION - * - * 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); +#define SILC_SF_NONE 0 +#define SILC_SF_INBUF_PENDING 1 /* data in inbound buffer */ +#define SILC_SF_OUTBUF_PENDING 2 /* data in outbound buffer */ +#define SILC_SF_DISCONNECTING 3 /* socket disconnecting */ +#define SILC_SF_DISCONNECTED 4 /* socket disconnected */ +#define SILC_SF_HOST_LOOKUP 5 /* performing host lookup for socket */ +#define SILC_SF_DISABLED 6 /* socket connection is disabled, + no data is sent or received. */ /****s* silcutil/SilcSocketConnectionAPI/SilcSocketConnectionStruct * @@ -156,7 +142,7 @@ typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, * Protocol object for the socket. Currently only one protocol can be * executing at a time for a particular socket. * - * uint32 flags + * SilcUInt32 flags * * Socket flags that indicate the status of the socket. This can * indicate several different status that can affect the use of the @@ -169,7 +155,7 @@ typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, * * char *hostname * char *ip - * uint16 port + * SilcUInt16 port * * Resolved hostname, IP address and port of the connection who owns * this object. @@ -192,12 +178,13 @@ struct SilcSocketConnectionStruct { SilcSocketType type; void *user_data; SilcProtocol protocol; - uint32 flags; + SilcUInt32 flags; + SilcUInt8 sock_error; int users; char *hostname; char *ip; - uint16 port; + SilcUInt16 port; SilcBuffer inbuf; SilcBuffer outbuf; @@ -207,6 +194,12 @@ struct SilcSocketConnectionStruct { /* Macros */ +/* Amount of bytes to be read from the socket connection at once. */ +#define SILC_SOCKET_READ_SIZE 16384 + +/* Default socket buffer size. */ +#define SILC_SOCKET_BUF_SIZE 1024 + /* Generic manipulation of flags */ #define SF_SET(x, f) (x)->flags |= (1L << (f)) #define SF_UNSET(x, f) (x)->flags &= ~(1L << (f)) @@ -217,16 +210,22 @@ struct SilcSocketConnectionStruct { #define SILC_SET_INBUF_PENDING(x) SF_SET((x), SILC_SF_INBUF_PENDING) #define SILC_SET_DISCONNECTING(x) SF_SET((x), SILC_SF_DISCONNECTING) #define SILC_SET_DISCONNECTED(x) SF_SET((x), SILC_SF_DISCONNECTED) +#define SILC_SET_HOST_LOOKUP(x) SF_SET((x), SILC_SF_HOST_LOOKUP) +#define SILC_SET_DISABLED(x) SF_SET((x), SILC_SF_HOST_LOOKUP) #define SILC_UNSET_OUTBUF_PENDING(x) SF_UNSET((x), SILC_SF_OUTBUF_PENDING) #define SILC_UNSET_INBUF_PENDING(x) SF_UNSET((x), SILC_SF_INBUF_PENDING) #define SILC_UNSET_DISCONNECTING(x) SF_UNSET((x), SILC_SF_DISCONNECTING) #define SILC_UNSET_DISCONNECTED(x) SF_UNSET((x), SILC_SF_DISCONNECTED) +#define SILC_UNSET_HOST_LOOKUP(x) SF_UNSET((x), SILC_SF_HOST_LOOKUP) +#define SILC_UNSET_DISABLED(x) SF_UNSET((x), SILC_SF_DISABLED) /* Checking for flags */ #define SILC_IS_OUTBUF_PENDING(x) SF_IS((x), SILC_SF_OUTBUF_PENDING) #define SILC_IS_INBUF_PENDING(x) SF_IS((x), SILC_SF_INBUF_PENDING) #define SILC_IS_DISCONNECTING(x) SF_IS((x), SILC_SF_DISCONNECTING) #define SILC_IS_DISCONNECTED(x) SF_IS((x), SILC_SF_DISCONNECTED) +#define SILC_IS_HOST_LOOKUP(x) SF_IS((x), SILC_SF_HOST_LOOKUP) +#define SILC_IS_DISABLED(x) SF_IS((x), SILC_SF_DISABLED) /* Prototypes */ @@ -291,7 +290,7 @@ SilcSocketConnection silc_socket_dup(SilcSocketConnection sock); * Reads data from the socket connection into the incoming data buffer. * It reads as much as possible from the socket connection. This returns * amount of bytes read or -1 on error or -2 on case where all of the - * data could not be read at once. Implementation of this funtion + * data could not be read at once. Implementation of this function * may be platform specific. * ***/ @@ -301,7 +300,7 @@ int silc_socket_read(SilcSocketConnection sock); * * SYNOPSIS * - * int silc_socket_read(SilcSocketConnection sock); + * int silc_socket_write(SilcSocketConnection sock); * * DESCRIPTION * @@ -309,21 +308,55 @@ int silc_socket_read(SilcSocketConnection sock); * data cannot be written at once, it must be written at later time. * The data is written from the data section of the buffer, not from head * or tail section. This automatically pulls the data section towards end - * after writing the data. Implementation of this functions may be + * after writing the data. Implementation of this function may be * platform specific. * ***/ int silc_socket_write(SilcSocketConnection sock); +/****f* silcutil/SilcSocketConnectionAPI/silc_socket_get_error + * + * SYNOPSIS + * + * bool silc_socket_get_error(SilcSocketConnection sock, char *error, + * SilcUInt32 error_len); + * + * DESCRIPTION + * + * Returns human readable error message into the `error' buffer if + * the socket is in error status. Returns TRUE if error message was + * written into the buffer and FALSE if there is not socket error. + * + ***/ +bool silc_socket_get_error(SilcSocketConnection sock, char *error, + SilcUInt32 error_len); + +/****f* silcutil/SilcSocketConnectionAPI/SilcSocketConnectionHBCb + * + * SYNOPSIS + * + * typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, + * void *context); + * + * DESCRIPTION + * + * 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); + /****f* silcutil/SilcSocketConnectionAPI/silc_socket_set_heartbeat * * SYNOPSIS * * void silc_socket_set_heartbeat(SilcSocketConnection sock, - * uint32 heartbeat, + * SilcUInt32 heartbeat, * void *hb_context, * SilcSocketConnectionHBCb hb_callback, - * void *timeout_queue); + * SilcSchedule schedule); * * DESCRIPTION * @@ -333,13 +366,65 @@ int silc_socket_write(SilcSocketConnection sock); * `hb_callback' function that is called when the `heartbeat' timeout * expires. The callback `hb_context' won't be touched by the library * but will be freed automatically when calling silc_socket_free. The - * `timeout_queue' is the application's scheduler timeout queue. + * `schedule' is the application's scheduler. * ***/ void silc_socket_set_heartbeat(SilcSocketConnection sock, - uint32 heartbeat, + SilcUInt32 heartbeat, void *hb_context, SilcSocketConnectionHBCb hb_callback, - void *timeout_queue); + SilcSchedule schedule); + +/****f* silcutil/SilcSocketConnectionAPI/SilcSocketHostLookupCb + * + * SYNOPSIS + * + * typedef void (*SilcSocketHostLookupCb)(SilcSocketConnection sock, + * void *context); + * + * DESCRIPTION + * + * Asynchronous host lookup callback function that will be called + * when the lookup is performed. + * + ***/ +typedef void (*SilcSocketHostLookupCb)(SilcSocketConnection sock, + void *context); + +/****f* silcutil/SilcSocketConnectionAPI/silc_socket_host_lookup + * + * SYNOPSIS + * + * void silc_socket_host_lookup(SilcSocketConnection sock, + * bool port_lookup, + * SilcSocketHostLookupCb callback, + * void *context, + * SilcSchedule schedule); + * + * DESCRIPTION + * + * Performs asynchronous host name and IP address lookups for the + * specified socket connection. This may be called when the socket + * connection is created and the full IP address and fully qualified + * domain name information is desired. The `callback' with `context' + * will be called after the lookup is performed. The `schedule' + * is the application's scheduler which the lookup routine needs. + * If the socket connection is freed during the lookup the library + * will automatically cancel the lookup and the `callback' will not be + * called. + * + * If `port_lookup' is TRUE then the remote port of the socket + * connection is resolved. After the information is resolved they + * are accessible using sock->ip and sock->hostname pointers. Note + * that if the both IP and FQDN could not be resolved the sock->hostname + * includes the IP address of the remote host. The resolved port is + * available in sock->port. + * + ***/ +void silc_socket_host_lookup(SilcSocketConnection sock, + bool port_lookup, + SilcSocketHostLookupCb callback, + void *context, + SilcSchedule schedule); #endif