/Conn.h (e2302f47f9beb6d949268fee80c918298c6701a1) (7051 bytes) (mode 100644) (type blob)
#ifndef _Conn_h
#define _Conn_h 1
#define _GNU_SOURCE
#include <stdarg.h>
#include <resolv.h>
#include <errno.h>
#include <signal.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/poll.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
/* type */
#define Conn_type_MASTER 1
#define Conn_type_CLIENT 2
#define Conn_type_UNK 3
/* state */
#define CONN_STATE_START 0
#define CONN_STATE_FREE CONN_STATE_START + 1
#define CONN_STATE_EMPTY CONN_STATE_START + 2
#define CONN_STATE_OPEN CONN_STATE_START + 3
#define CONN_STATE_LISTEN CONN_STATE_START + 4
#define CONN_STATE_CONNECT_0 CONN_STATE_START + 5
#define CONN_STATE_CONNECT_a CONN_STATE_START + 6
#define CONN_STATE_CONNECT_b CONN_STATE_START + 7
/* error kind */
#define CONN_ERROR_START 0
#define CONN_ERROR_USERREQ CONN_ERROR_START + 1 /* user requested the close */
#define CONN_ERROR_POLL CONN_ERROR_START + 2
#define CONN_ERROR_RECV CONN_ERROR_START + 3
#define CONN_ERROR_SEND CONN_ERROR_START + 4
#define CONN_ERROR_SOCKET CONN_ERROR_START + 5
#define CONN_ERROR_HANGUP CONN_ERROR_START + 6
#define CONN_ERROR_GETADDRINFO CONN_ERROR_START + 7
#define CONN_ERROR_EXPIRED CONN_ERROR_START + 8
#define CONN_ERROR_ACCEPT CONN_ERROR_START + 9
#define CONN_ERROR_MEM CONN_ERROR_START + 10
#define CONN_ERROR_CONNECT CONN_ERROR_START + 11
#define CONN_ERROR_READ_TIMEOUT CONN_ERROR_START + 12
#define CONN_ERROR_CONN_TIMEOUT CONN_ERROR_START + 13
/* FLAGS */
#define CONN_FLAGS_AUTO_RECONNECT 0x01 << 0
#define CONN_FLAGS_CLOSE_AFTER_SEND 0x01 << 1
/* Parameters */
#define CONN_PARA_START 0
#define CONN_PARA_AUTO_RECONNECT CONN_PARA_START + 1
#define CONN_PARA_RECONNECT_DELAY CONN_PARA_START + 2
#define CONN_PARA_IDLE_TIME CONN_PARA_START + 3
#define CONN_PARA_READ_TIMEOUT CONN_PARA_START + 4
#define CONN_PARA_CONN_TIMEOUT CONN_PARA_START + 5
#define CONN_PARA_TRIGGER CONN_PARA_START + 6
#define CONN_PARA_IBUF CONN_PARA_START + 7
#define CONN_PARA_OBUF CONN_PARA_START + 8
/* Callbacks */
#define CONN_CB_START 0
#define CONN_CB_ACCEPT CONN_CB_START + 1
#define CONN_CB_RECV CONN_CB_START + 2
#define CONN_CB_SEND CONN_CB_START + 3
#define CONN_CB_DATA CONN_CB_START + 4
#define CONN_CB_CLOSE CONN_CB_START + 5
#define CONN_CB_TRIGGER CONN_CB_START + 6
#define CONN_CB_ERROR CONN_CB_START + 7
#define CONN_CB_CONNECTED CONN_CB_START + 8
struct Conn
{
unsigned char type;
unsigned char state;
unsigned char error_state;
unsigned int slot;
char *ibuf;
unsigned int ibuf_size, ibuf_head, ibuf_tail;
char *obuf;
unsigned int obuf_size, obuf_head, obuf_tail;
struct timeval trecv, tsend; /* last time we saw an receive/send */
unsigned int idle; /* idle time allowed */
unsigned int read_timeout; /* Max timeout for receiving an answer (milliseconds) */
struct timeval conn_syn; /* Time when a connection was initiated */
unsigned int conn_timeout; /* Timeout for connection (milliseconds) */
time_t last_trigger; /* last trigger was at */
unsigned int trigger; /* Frequency of wakeup a connection */
int sock_domain;
int sock_type;
char addr[64];
int port, via; /* "via" is the port via a client was accepted */
unsigned long long bi, bo;
void *private; /* private use by user */
/* reconnect stuff */
unsigned int retries;
unsigned int delay; /* delay between reconnects */
time_t tryat; /* when we go to CONNECT_a state */
int xerrno;
time_t start;
unsigned int flags;
/* bandwidth stuff */
struct timeval band_lasttime; /* last time tokens were added */
unsigned int band_tokens; /* 1 token -> 1000 bytes */
unsigned int band_factor; /* tokens cannot go past f * w */
unsigned int band_width; /* in 1000b increments */
unsigned long long id; /* the id of a connection */
/* Specific callbacks */
void (*cb_accept)(struct Conn *C);
void (*cb_recv)(struct Conn *C);
void (*cb_send)(struct Conn *C);
void (*cb_data)(struct Conn *C);
void (*cb_close)(struct Conn *C);
void (*cb_trigger)(struct Conn *C);
void (*cb_error)(struct Conn *C);
void (*cb_connected)(struct Conn *C);
};
/* Variables */
extern void (*Conn_accept_cb)(struct Conn *C);
extern void (*Conn_recv_cb)(struct Conn *C);
extern void (*Conn_send_cb)(struct Conn *C);
extern void (*Conn_data_cb)(struct Conn *C);
extern void (*Conn_close_cb)(struct Conn *C);
extern void (*Conn_trigger_cb)(struct Conn *C);
extern void (*Conn_error_cb)(struct Conn *C);
extern void (*Conn_connected_cb)(struct Conn *C);
extern char *(*Conn_status_slot_html_cb)(struct Conn *C);
extern char *(*Conn_status_cb)(void);
extern unsigned int Conn_max_reached;
extern unsigned int Conn_default_ibuf;
extern unsigned int Conn_default_obuf;
extern unsigned int Conn_max_ibuf;
extern unsigned int Conn_max_obuf;
extern unsigned int Conn_no;
extern unsigned int Conn_max;
extern unsigned long Conn_total;
extern unsigned int Conn_start;
extern unsigned int Conn_pending;
extern struct timeval Conn_now;
extern unsigned int Conn_max_send;
extern unsigned int Conn_max_recv;
extern unsigned short Conn_level;
/* Functions */
extern char *Conn_strerror(void);
extern int Conn_init(unsigned int max);
extern void Conn_close(struct Conn *C);
extern ssize_t Conn_send(struct Conn *C, void *buf, size_t count);
extern ssize_t Conn_recv(struct Conn *C, void *buf, size_t count);
extern struct Conn *Conn_socket(int domain, int type, int port);
extern char *Conn_status(unsigned int flags);
extern int Conn_poll(int timeout);
extern int Conn_enqueue(struct Conn *C, void *buf, size_t count);
extern void Conn_debug(FILE *f, unsigned short debug);
extern struct Conn *Conn_connect(int domain, int type, char *addr, int port);
extern char *Conn_dump(char *buf_src, int len_src);
extern char *Conn_dumphex(char *buf_src, int len_src);
extern int Conn_nodelay(struct Conn *C);
extern void Conn_rollback(struct Conn *C, unsigned int bytes);
extern char *Conn_strstr(struct Conn *C, char *str);
extern unsigned int Conn_qlen(struct Conn *C);
extern void Conn_eat(struct Conn *C, unsigned int bytes);
extern void Conn_eatall(struct Conn *C);
extern char *Conn_ibuf(struct Conn *C);
extern char *Conn_obuf(struct Conn *C);
extern int Conn_try_expand_buf(struct Conn *C, int what, int needed);
extern int Conn_band(struct Conn *C, unsigned int width, unsigned int factor);
extern void Conn_set(struct Conn *C, int var, unsigned int val);
extern char *Conn_ostrstr(struct Conn *C, unsigned int off, char *str);
extern unsigned long long Conn_getid(struct Conn *C);
extern struct Conn *Conn_get(unsigned long long id);
extern int Conn_get_fd(struct Conn *C);
extern void Conn_last_time(struct Conn *C, struct timeval *tv);
extern int Conn_set_cb(struct Conn *C, unsigned int type,
void (*f)(struct Conn *));
#endif
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
1945 |
fecf0e7a7e8580485101a179685aedc7e00affbb |
Changelog |
100644 |
blob |
39966 |
3101607ebe0288de591acda2d558579b4c54ccac |
Conn.c |
100644 |
blob |
7051 |
e2302f47f9beb6d949268fee80c918298c6701a1 |
Conn.h |
100644 |
blob |
717 |
1394784a1fafde8f15d3fba489c056bc045a8003 |
Conn.spec.in |
100644 |
blob |
30 |
d987fa5df957830331139935d517009e2911b0cf |
INSTALL |
100644 |
blob |
25275 |
92b8903ff3fea7f49ef5c041b67a087bca21c5ec |
LICENSE |
100644 |
blob |
498 |
9b760aafe85b71ce4d52b50f6b55ff73cff7bfc6 |
Makefile.head |
100644 |
blob |
710 |
570276f936ae7d28a85c1c29c92645f3ba6a9543 |
Makefile.in |
100644 |
blob |
462 |
1b23184ebfd6fb72c20de1e4b011f15aaffb214f |
Makefile.tail |
100644 |
blob |
4 |
c4846601e2d94d4ee8b2c17cc37c0a829c49d1e9 |
PROJECT |
100644 |
blob |
0 |
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 |
PROJECT_EXCLUDE |
100644 |
blob |
3 |
8f92bfdd49766b1907d4aec8d3b0f9ed6129d0e6 |
PROJECT_REV |
100644 |
blob |
4 |
0702cb5bfbb0169457c00f947f4e5601f8cd77e7 |
PROJECT_TARGETS |
100644 |
blob |
6 |
b0f3d96f877256ed9ae03858ecc5185a989b1d1b |
PROJECT_VER |
100644 |
blob |
192 |
5b11bdfb23857d8588845465aef993b320596b44 |
README |
100644 |
blob |
1453 |
b9f9dab2d0bb2762dea406c9e87d34eb38a18d9d |
TODO |
100755 |
blob |
2315 |
11e05cc644a8af4277006af69d78277a143590c4 |
configure |
040000 |
tree |
- |
d4c9c4a69c5cfa2a84316967185f1661b6817779 |
docs |
040000 |
tree |
- |
a4c21858806284281d1fe8479845411711694ebb |
examples |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/Conn
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/Conn
Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/Conn
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main