aboutsummaryrefslogtreecommitdiffstats
path: root/sock_conn.h
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-05-11 16:45:00 +0100
committerFreeArtMan <dos21h@gmail.com>2017-05-11 16:45:00 +0100
commit1e8e7cf72de6ca97b8e8cd3ba4266788ba9fec53 (patch)
tree878d3d9a46db60a156935c41307b83c39c0d42c8 /sock_conn.h
parent6a377350d63fc2dd470e9bd25008e8e827c011f2 (diff)
downloadagni-1e8e7cf72de6ca97b8e8cd3ba4266788ba9fec53.tar.gz
agni-1e8e7cf72de6ca97b8e8cd3ba4266788ba9fec53.zip
Update socket connection functions. Now reconnection is possible
Diffstat (limited to 'sock_conn.h')
-rw-r--r--sock_conn.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/sock_conn.h b/sock_conn.h
index 55ef8e0..8cf64be 100644
--- a/sock_conn.h
+++ b/sock_conn.h
@@ -3,9 +3,15 @@
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <unistd.h>
#include <netdb.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <errno.h>
#include "util.h"
@@ -38,7 +44,42 @@ int irc_buf_ready(irc_buf *ib);
char *irc_buf_line(irc_buf *ib);
int irc_buf_destroy(irc_buf *ib);
+//connecto to irc
+typedef struct irc_conn
+{
+ int conn_fd; //save connection fd
+ char *hostname;
+ char *port;
+ struct timespec last_read; //when last read where happening
+ int timeout;
+ int err; //local error type
+ int liberr; //save error from libc
+} irc_conn;
+
int irc_connect(char *hostname, char *port);
+//list of errors that will give more precise error description, if there is -1 returned one of this errors happened
+#define ERR_SC_NONE 0 //no errors
+#define ERR_SC_LIBC 1 //error from libc, dont have our own error
+#define ERR_SC_PARAM 2 //something wrong with given params
+#define ERR_SC_TIMEOUT 3 //timeout
+#define ERR_SC_ALLOC 4 //memory allocation error
+#define ERR_SC_CONN 5 //somethign with network connection
+#define ERR_SC_RXTX 6 //read/write issue
+#define ERR_SC_AGAIN 7 //async stuff try read later
+#define ERR_SC_ANY 8 //any other error
+
+//irc_conn preallocated, artifacts can stay if something whent wrong
+int irc_open(char *hostname, char *port, irc_conn *conn);
+//if havent readed for more then [timeout] seconds then assume no connection
+int irc_read_timeout(irc_conn *conn, int timeout);
+//wrapped up usual read, read non blocking, count how long there was no data,
+//and asks to reconnect, use err/liberr to diagnose error
+int irc_read(irc_conn *conn, char *buf, size_t sz);
+//no extra errors
+int irc_reconnect(irc_conn *conn);
+//clean dont free
+int irc_close(irc_conn *conn);
+
#endif