File: sockdev.h

package info (click to toggle)
hercules 3.13-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,392 kB
  • sloc: ansic: 175,124; sh: 8,792; makefile: 760; perl: 149
file content (52 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* SOCKDEV.H    (c) Copyright Malcolm Beattie, 2001                  */
/*              Hercules socket device header file                   */

#include "htypes.h"

#ifndef _SOCKDEV_H_
#define _SOCKDEV_H_

/*-------------------------------------------------------------------*/
/* The sockdev callback function is an optional callback function    */
/* that the sockdev connection handler calls after the connection    */
/* has been established but before it has logged the connection to   */
/* the console. The boolean return code from the callback indicates  */
/* true or false (!0 or 0) whether the connection should be accepted */
/* or not. If the return from the callback is 0 (false), the socket  */
/* is immediately closed and the "connection not accepted" message   */
/* is logged to the console. You should NOT perform any significant  */
/* processing in your callback. If you need to do any significant    */
/* processing you should instead create a worker to perform it in.   */
/*-------------------------------------------------------------------*/

typedef int (*ONCONNECT)( DEVBLK* );     // onconnect callback function (opt)

/*-------------------------------------------------------------------*/
/* Bind structure for "Socket Devices"                               */
/*-------------------------------------------------------------------*/

struct bind_struct          // Bind structure for "Socket Devices"
{
    LIST_ENTRY  bind_link;  // (just a link in the chain)

    DEVBLK  *dev;           // ptr to corresponding device block
    char    *spec;          // socket_spec for listening socket
    int      sd;            // listening socket to use in select

                            // NOTE: Following 2 fields malloc'ed.
    char    *clientname;    // connected client's hostname
    char    *clientip;      // conencted client's ip address

    ONCONNECT    fn;        // ptr to onconnect callback func (opt)
    void        *arg;       // argument for callback function (opt)
};

/* "Socket Device" functions */

extern        int bind_device_ex   (DEVBLK* dev, char* spec, ONCONNECT fn, void* arg );
extern        int unbind_device_ex (DEVBLK* dev, int forced);

static inline int bind_device      (DEVBLK* dev, char* spec) { return bind_device_ex   ( dev, spec, NULL, NULL ); }
static inline int unbind_device    (DEVBLK* dev)             { return unbind_device_ex ( dev, 0 );                }

#endif // _SOCKDEV_H_