root/net/kern_sock.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef _KERN_SOCK_H
   2 #define _KERN_SOCK_H
   3 #undef SOCK_DEBUG
   4 #define NSOCKETS 128                    /* should be dynamic, later... */
   5 
   6 typedef enum {
   7         SS_FREE = 0,                    /* not allocated */
   8         SS_UNCONNECTED,                 /* unconnected to any socket */
   9         SS_CONNECTING,                  /* in process of connecting */
  10         SS_CONNECTED,                   /* connected to socket */
  11         SS_DISCONNECTING,               /* in process of disconnecting */
  12 } socket_state;
  13 
  14 #define SO_ACCEPTCON    (1<<16)         /* performed a listen */
  15 
  16 /*
  17  * internel representation of a socket. not all the fields are used by
  18  * all configurations:
  19  *
  20  *              server                  client
  21  * conn         client connected to     server connected to
  22  * iconn        list of clients         -unused-
  23  *               awaiting connections
  24  * wait         sleep for clients,      sleep for connection,
  25  *              sleep for i/o           sleep for i/o
  26  */
  27 struct socket {
  28         short type;                     /* SOCK_STREAM, ... */
  29         socket_state state;
  30         long flags;
  31         struct proto_ops *ops;          /* protocols do most everything */
  32         void *data;                     /* protocol data */
  33         struct socket *conn;            /* server socket connected to */
  34         struct socket *iconn;           /* incomplete client connections */
  35         struct socket *next;
  36         struct wait_queue **wait;       /* ptr to place to wait on */
  37         void *dummy;
  38 };
  39 
  40 #define SOCK_INODE(S) ((struct inode *)(S)->dummy)
  41 extern struct socket sockets[NSOCKETS];
  42 #define last_socket (sockets + NSOCKETS - 1)
  43 
  44 struct proto_ops {
  45         int (*init)(void);
  46         int (*create)(struct socket *sock, int protocol);
  47         int (*dup)(struct socket *newsock, struct socket *oldsock);
  48         int (*release)(struct socket *sock, struct socket *peer);
  49         int (*bind)(struct socket *sock, struct sockaddr *umyaddr,
  50                     int sockaddr_len);
  51         int (*connect)(struct socket *sock, struct sockaddr *uservaddr,
  52                        int sockaddr_len, int flags);
  53         int (*socketpair)(struct socket *sock1, struct socket *sock2);
  54         int (*accept)(struct socket *sock, struct socket *newsock, int flags);
  55         int (*getname)(struct socket *sock, struct sockaddr *uaddr,
  56                        int *usockaddr_len, int peer);
  57         int (*read)(struct socket *sock, char *ubuf, int size, int nonblock);
  58         int (*write)(struct socket *sock, char *ubuf, int size, int nonblock);
  59         int (*select)(struct socket *sock, int sel_type, select_table * wait);
  60         int (*ioctl)(struct socket *sock, unsigned int cmd, unsigned long arg);
  61         int (*listen)(struct socket *sock, int len);
  62         int (*send)(struct socket *sock, void *buff, int len, int nonblock,
  63                     unsigned flags);
  64         int (*recv)(struct socket *sock, void *buff, int len, int nonblock,
  65                     unsigned flags);
  66         int (*sendto)(struct socket *sock, void *buff, int len, int nonblock,
  67                       unsigned flags, struct sockaddr *, int addr_len);
  68         int (*recvfrom)(struct socket *sock, void *buff, int len, int nonblock,
  69                         unsigned flags, struct sockaddr *, int *addr_len);
  70         int (*shutdown)(struct socket *sock, int flags);
  71         int (*setsockopt)(struct socket *sock, int level, int optname,
  72                           char *optval, int optlen);
  73         int (*getsockopt)(struct socket *sock, int level, int optname,
  74                           char *optval, int *optlen);
  75         int (*fcntl) (struct socket *sock, unsigned int cmd,
  76                       unsigned long arg);       
  77 };
  78 
  79 extern int sock_awaitconn(struct socket *mysock, struct socket *servsock);
  80 
  81 #ifdef SOCK_DEBUG
  82 #define PRINTK(x) printk x
  83 #else
  84 #define PRINTK(x) /**/
  85 #endif
  86 
  87 #endif /* _KERN_SOCK_H */

/* [previous][next][first][last][top][bottom][index][help] */