#ifndef __AGNI_SOCK_CONN_H #define __AGNI_SOCK_CONN_H #include #include #include #include #include #include #include #include #include #include #include #include "util.h" #include "debug.h" #define IRC_BUF_IN_SIZE 1024*64 #define IRC_BUF_OUT_SIZE 1024 /* Reads ins and spils out IRC lines ended with \r\n. */ //?what will happend if there is no string consumer? typedef struct irc_buf { int out_size; int max_out_size; int in_size; int max_in_size; char *buf_in; char *buf_out; int ready;//if 1 there is one full line } irc_buf; irc_buf* irc_buf_create(); //put string inside in reverse order =P int irc_buf_puts(irc_buf *ib, char *in_buf, int sz); int irc_buf_putc(irc_buf *ib, char c); int irc_buf_sz(irc_buf *ib); 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