updates
[silc.git] / lib / silcutil / silcsockconn.h
index f2e15e3cd1dd177dd28b8b7d6a7bda590c299bca..d7acdf95834fec56ec665effca95ac3846eeb539 100644 (file)
@@ -18,7 +18,7 @@
 
 */
 
-/****h* silcutil/SilcSocketConnectionAPI
+/****h* silcutil/SILC Socket Interface
  *
  * DESCRIPTION
  *
@@ -142,7 +142,7 @@ typedef enum {
  *      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
@@ -153,12 +153,9 @@ typedef enum {
  *      Reference counter. When allocated it is set to one (1) and it won't
  *      be freed until it hits zero (0).
  *
- *    char *hostname
- *    char *ip
- *    uint16 port
+ *    SilcSocketConnectionHB hb
  *
- *      Resolved hostname, IP address and port of the connection who owns
- *      this object.
+ *      The heartbeat context.  If NULL, heartbeat is not performed.
  *
  *    SilcBuffer inbuf
  *    SilcBuffer outbuf
@@ -168,9 +165,12 @@ typedef enum {
  *      inbuf buffer and outgoing data after encryption is put to the outbuf
  *      buffer.
  *
- *    SilcSocketConnectionHB hb
+ *    char *hostname
+ *    char *ip
+ *    SilcUInt16 port
  *
- *      The heartbeat context.  If NULL, heartbeat is not performed.
+ *      Resolved hostname, IP address and port of the connection who owns
+ *      this object.
  *
  ***/
 struct SilcSocketConnectionStruct {
@@ -178,21 +178,26 @@ struct SilcSocketConnectionStruct {
   SilcSocketType type;
   void *user_data;
   SilcProtocol protocol;
-  uint32 flags;
+  SilcUInt32 flags;
   int users;
 
-  char *hostname;
-  char *ip;
-  uint16 port;
+  SilcSocketConnectionHB hb;
 
   SilcBuffer inbuf;
   SilcBuffer outbuf;
 
-  SilcSocketConnectionHB hb;
+  char *hostname;
+  char *ip;
+  SilcUInt16 port;
+  SilcUInt8 sock_error;
+  SilcUInt8 version;
 };
 
 /* Macros */
 
+/* Check for specific protocol version */
+#define SILC_PROTOCOL_VERSION(s, maj, min) (s->version == maj##min)
+
 /* Amount of bytes to be read from the socket connection at once. */
 #define SILC_SOCKET_READ_SIZE 16384
 
@@ -299,7 +304,7 @@ int silc_socket_read(SilcSocketConnection sock);
  *
  * SYNOPSIS
  *
- *    int silc_socket_read(SilcSocketConnection sock);
+ *    int silc_socket_write(SilcSocketConnection sock);
  *
  * DESCRIPTION
  *
@@ -313,6 +318,23 @@ int silc_socket_read(SilcSocketConnection sock);
  ***/
 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
@@ -335,7 +357,7 @@ typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock,
  * SYNOPSIS
  *
  *    void silc_socket_set_heartbeat(SilcSocketConnection sock, 
- *                                   uint32 heartbeat,
+ *                                   SilcUInt32 heartbeat,
  *                                   void *hb_context,
  *                                   SilcSocketConnectionHBCb hb_callback,
  *                                   SilcSchedule schedule);
@@ -352,7 +374,7 @@ typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock,
  *
  ***/
 void silc_socket_set_heartbeat(SilcSocketConnection sock, 
-                              uint32 heartbeat,
+                              SilcUInt32 heartbeat,
                               void *hb_context,
                               SilcSocketConnectionHBCb hb_callback,
                               SilcSchedule schedule);