1 /* SOCKDEV.H    (c) Copyright Malcolm Beattie, 2001                  */
2 /*              Hercules socket device header file                   */
3 
4 #include "htypes.h"
5 
6 #ifndef _SOCKDEV_H_
7 #define _SOCKDEV_H_
8 
9 /*-------------------------------------------------------------------*/
10 /* The sockdev callback function is an optional callback function    */
11 /* that the sockdev connection handler calls after the connection    */
12 /* has been established but before it has logged the connection to   */
13 /* the console. The boolean return code from the callback indicates  */
14 /* true or false (!0 or 0) whether the connection should be accepted */
15 /* or not. If the return from the callback is 0 (false), the socket  */
16 /* is immediately closed and the "connection not accepted" message   */
17 /* is logged to the console. You should NOT perform any significant  */
18 /* processing in your callback. If you need to do any significant    */
19 /* processing you should instead create a worker to perform it in.   */
20 /*-------------------------------------------------------------------*/
21 
22 typedef int (*ONCONNECT)( DEVBLK* );     // onconnect callback function (opt)
23 
24 /*-------------------------------------------------------------------*/
25 /* Bind structure for "Socket Devices"                               */
26 /*-------------------------------------------------------------------*/
27 
28 struct bind_struct          // Bind structure for "Socket Devices"
29 {
30     LIST_ENTRY  bind_link;  // (just a link in the chain)
31 
32     DEVBLK  *dev;           // ptr to corresponding device block
33     char    *spec;          // socket_spec for listening socket
34     int      sd;            // listening socket to use in select
35 
36                             // NOTE: Following 2 fields malloc'ed.
37     char    *clientname;    // connected client's hostname
38     char    *clientip;      // conencted client's ip address
39 
40     ONCONNECT    fn;        // ptr to onconnect callback func (opt)
41     void        *arg;       // argument for callback function (opt)
42 };
43 
44 /* "Socket Device" functions */
45 
46 extern        int bind_device_ex   (DEVBLK* dev, char* spec, ONCONNECT fn, void* arg );
47 extern        int unbind_device_ex (DEVBLK* dev, int forced);
48 
bind_device(DEVBLK * dev,char * spec)49 static inline int bind_device      (DEVBLK* dev, char* spec) { return bind_device_ex   ( dev, spec, NULL, NULL ); }
unbind_device(DEVBLK * dev)50 static inline int unbind_device    (DEVBLK* dev)             { return unbind_device_ex ( dev, 0 );                }
51 
52 #endif // _SOCKDEV_H_
53