Browse code

socklib: add sock_setsafe

Dario Rodriguez authored on 18/05/2015 19:39:12
Showing 1 changed files
... ...
@@ -53,5 +53,6 @@ int sselect_getwritefiltered(sselect *ssel, fd_set *filter, int *fds, int sizefd
53 53
 /* socket configuration functions */
54 54
 void sock_setfast(int fd); /* mark as low-bandwidth interactive stream */
55 55
 void sock_setunsafe(int fd); /* for server sockets, configure reuseaddress, linger: only suitable for intranet usage */
56
+void sock_setsafe(int fd); /* for non-server sockets, configure reuseaddress, linger: make them suitable for internet usage */
56 57
 
57 58
 #endif
Browse code

socklib: add sock_readble()

Dario Rodriguez authored on 01/07/2014 09:30:17
Showing 1 changed files
... ...
@@ -32,6 +32,7 @@ int sock_accept(int fd);
32 32
 int sock_getinfo(int fd, int *iplen, char *ip, int *port); /* ip must be at least 16 bytes to have room for an ipv6 address */
33 33
 int sock_queued(int fd);
34 34
 int sock_setblocking(int fd, int block);
35
+int sock_readable(int fd);
35 36
 
36 37
 sselect *sselect_init(void);
37 38
 void sselect_free(sselect *ssel);
Browse code

webkernel: init, free, start of service and structures of clients

Dario Rodriguez authored on 13/06/2014 11:16:28
Showing 1 changed files
... ...
@@ -17,6 +17,7 @@
17 17
 
18 18
 #ifndef SOCKLIB_H
19 19
 #define SOCKLIB_H
20
+#include <sys/select.h> /* fd_set */
20 21
 
21 22
 typedef void sselect;
22 23
 
Browse code

socklib: add per-fd userptr

Dario Rodriguez authored on 12/06/2014 11:21:04
Showing 1 changed files
... ...
@@ -33,14 +33,16 @@ int sock_queued(int fd);
33 33
 int sock_setblocking(int fd, int block);
34 34
 
35 35
 sselect *sselect_init(void);
36
+void sselect_free(sselect *ssel);
36 37
 int sselect_reset(sselect *ssel);
37
-int sselect_addread(sselect *ssel, int fd);
38
-int sselect_addwrite(sselect *ssel, int fd);
38
+int sselect_addread(sselect *ssel, int fd, void *userptr);
39
+int sselect_addwrite(sselect *ssel, int fd, void *userptr);
39 40
 int sselect_delread(sselect *ssel, int fd);
40 41
 int sselect_delwrite(sselect *ssel, int fd);
41 42
 int sselect_wait(sselect *ssel, int ms);
42 43
 int sselect_getread(sselect *ssel, int *fds, int sizefds);
43 44
 int sselect_getwrite(sselect *ssel, int *fds, int sizefds);
45
+void *sselect_getuserptr(sselect *ssel, int fd);
44 46
 
45 47
 /* advanced sselect functions */
46 48
 int sselect_getreadfiltered(sselect *ssel, fd_set *filter, int *fds, int sizefds);
Browse code

socklib: add getreadfiltered()/getwritefiltered()

Dario Rodriguez authored on 11/06/2014 10:13:57
Showing 1 changed files
... ...
@@ -8,12 +8,6 @@
8 8
  * is to integrate the sock_connect() timeout inside the main
9 9
  * loop as to don't be blocking.
10 10
  *
11
- * History:
12
- *      27/01/2014 Creation
13
- *       3/04/2014 Add async-connect functions, add fd_set to select
14
- *      27/05/2014 Rethought the API; separate ipv4 from general functions,
15
- *                 rework select so that epoll usage is possible.
16
- *
17 11
  * Documentation used:
18 12
  *   http://www.beej.us/guide/bgnet/output/html/multipage/getaddrinfoman.html
19 13
  *
... ...
@@ -48,6 +42,11 @@ int sselect_wait(sselect *ssel, int ms);
48 42
 int sselect_getread(sselect *ssel, int *fds, int sizefds);
49 43
 int sselect_getwrite(sselect *ssel, int *fds, int sizefds);
50 44
 
45
+/* advanced sselect functions */
46
+int sselect_getreadfiltered(sselect *ssel, fd_set *filter, int *fds, int sizefds);
47
+int sselect_getwritefiltered(sselect *ssel, fd_set *filter, int *fds, int sizefds);
48
+
49
+/* socket configuration functions */
51 50
 void sock_setfast(int fd); /* mark as low-bandwidth interactive stream */
52 51
 void sock_setunsafe(int fd); /* for server sockets, configure reuseaddress, linger: only suitable for intranet usage */
53 52
 
Browse code

Implement the ipv4 part of socklib. Still lacking the sselect functions implementations.

Dario Rodriguez authored on 28/05/2014 12:11:17
Showing 1 changed files
... ...
@@ -24,19 +24,19 @@
24 24
 #ifndef SOCKLIB_H
25 25
 #define SOCKLIB_H
26 26
 
27
-typedef sselect void;
27
+typedef void sselect;
28 28
 
29 29
 char *ipv4_genip(char *hostname, long *resulthostsize);
30 30
 int ipv4_genport(char *portname, int fallback);
31 31
 int ipv4_preconnect(char *host, long hostsize, int port); /* setup socket, set non-blocking, connect(2) call */
32
-int ipv4_connect(int fd); /* tests writeability */
32
+int ipv4_connect(int fd, long timeoutmsec); /* tests writeability */
33 33
 int ipv4_postconnect(int fd); /* hopefully connect(2) suceeded, set blocking */
34 34
 int ipv4_server(int port);
35 35
 int ipv4_serverbinded(char *host, long hostsize, int port);
36 36
 int sock_accept(int fd);
37
-int sock_getinfo(int socket, int *iplen, char *ip, int *port); /* ip must be at least 16 bytes to have room for an ipv6 address */
38
-int sock_queued(int socket);
39
-int sock_setblocking(int socket, int block);
37
+int sock_getinfo(int fd, int *iplen, char *ip, int *port); /* ip must be at least 16 bytes to have room for an ipv6 address */
38
+int sock_queued(int fd);
39
+int sock_setblocking(int fd, int block);
40 40
 
41 41
 sselect *sselect_init(void);
42 42
 int sselect_reset(sselect *ssel);
... ...
@@ -44,7 +44,11 @@ int sselect_addread(sselect *ssel, int fd);
44 44
 int sselect_addwrite(sselect *ssel, int fd);
45 45
 int sselect_delread(sselect *ssel, int fd);
46 46
 int sselect_delwrite(sselect *ssel, int fd);
47
-int sselect_wait(sslect *ssel, int ms);
47
+int sselect_wait(sselect *ssel, int ms);
48 48
 int sselect_getread(sselect *ssel, int *fds, int sizefds);
49 49
 int sselect_getwrite(sselect *ssel, int *fds, int sizefds);
50
+
51
+void sock_setfast(int fd); /* mark as low-bandwidth interactive stream */
52
+void sock_setunsafe(int fd); /* for server sockets, configure reuseaddress, linger: only suitable for intranet usage */
53
+
50 54
 #endif
Browse code

API rework to accomodate ipv6 and epoll in the future

Dario Rodriguez authored on 27/05/2014 11:33:45
Showing 1 changed files
... ...
@@ -10,6 +10,12 @@
10 10
  *
11 11
  * History:
12 12
  *      27/01/2014 Creation
13
+ *       3/04/2014 Add async-connect functions, add fd_set to select
14
+ *      27/05/2014 Rethought the API; separate ipv4 from general functions,
15
+ *                 rework select so that epoll usage is possible.
16
+ *
17
+ * Documentation used:
18
+ *   http://www.beej.us/guide/bgnet/output/html/multipage/getaddrinfoman.html
13 19
  *
14 20
  * Author: Dario Rodriguez dario@softhome.net
15 21
  * This file is licensed under the terms of the GNU LGPL v2+
... ...
@@ -18,13 +24,27 @@
18 24
 #ifndef SOCKLIB_H
19 25
 #define SOCKLIB_H
20 26
 
21
-char *sock_genip(char *hostname, long *resulthostsize);
22
-int sock_genport(char *portname, int fallback);
23
-int sock_connect(char *host, long hostsize, int port);
24
-int sock_server(int port);
25
-int sock_serverbinded(char *host, long hostsize, int port);
26
-int sock_getinfo(int socket, char *ip, int *port);
27
-int sock_select(long timoutms, ...); /* int numfds, int *resfdreadgroup1, int *fdreadgroup1,...,-1,int numfds, int *resfdwritegroup1, int *fdwritegroup1,...,-1); */
27
+typedef sselect void;
28
+
29
+char *ipv4_genip(char *hostname, long *resulthostsize);
30
+int ipv4_genport(char *portname, int fallback);
31
+int ipv4_preconnect(char *host, long hostsize, int port); /* setup socket, set non-blocking, connect(2) call */
32
+int ipv4_connect(int fd); /* tests writeability */
33
+int ipv4_postconnect(int fd); /* hopefully connect(2) suceeded, set blocking */
34
+int ipv4_server(int port);
35
+int ipv4_serverbinded(char *host, long hostsize, int port);
36
+int sock_accept(int fd);
37
+int sock_getinfo(int socket, int *iplen, char *ip, int *port); /* ip must be at least 16 bytes to have room for an ipv6 address */
28 38
 int sock_queued(int socket);
29 39
 int sock_setblocking(int socket, int block);
40
+
41
+sselect *sselect_init(void);
42
+int sselect_reset(sselect *ssel);
43
+int sselect_addread(sselect *ssel, int fd);
44
+int sselect_addwrite(sselect *ssel, int fd);
45
+int sselect_delread(sselect *ssel, int fd);
46
+int sselect_delwrite(sselect *ssel, int fd);
47
+int sselect_wait(sslect *ssel, int ms);
48
+int sselect_getread(sselect *ssel, int *fds, int sizefds);
49
+int sselect_getwrite(sselect *ssel, int *fds, int sizefds);
30 50
 #endif
Browse code

Added current unfinished sources

Dario Rodriguez authored on 12/03/2014 11:38:34
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+/*
2
+ * socklib.h
3
+ *
4
+ * Handy functions for IPv4 socket sonnections.
5
+ *
6
+ * Limitations:
7
+ * These are for the simplest case, as the recommended approach
8
+ * is to integrate the sock_connect() timeout inside the main
9
+ * loop as to don't be blocking.
10
+ *
11
+ * History:
12
+ *      27/01/2014 Creation
13
+ *
14
+ * Author: Dario Rodriguez dario@softhome.net
15
+ * This file is licensed under the terms of the GNU LGPL v2+
16
+ */
17
+
18
+#ifndef SOCKLIB_H
19
+#define SOCKLIB_H
20
+
21
+char *sock_genip(char *hostname, long *resulthostsize);
22
+int sock_genport(char *portname, int fallback);
23
+int sock_connect(char *host, long hostsize, int port);
24
+int sock_server(int port);
25
+int sock_serverbinded(char *host, long hostsize, int port);
26
+int sock_getinfo(int socket, char *ip, int *port);
27
+int sock_select(long timoutms, ...); /* int numfds, int *resfdreadgroup1, int *fdreadgroup1,...,-1,int numfds, int *resfdwritegroup1, int *fdwritegroup1,...,-1); */
28
+int sock_queued(int socket);
29
+int sock_setblocking(int socket, int block);
30
+#endif