1 #ifndef __NET_SERVER_SOCKET_H__
2 #define __NET_SERVER_SOCKET_H__
7 #include <minix/endpoint.h>
8 #include <minix/chardriver.h>
11 * User can set this variable to make the debugging output differ between
12 * various users, e.g. "TCP" or "UDP"
14 extern char * netsock_user_name
;
16 #define SOCK_TYPE_IP 0
17 #define SOCK_TYPE_TCP 1
18 #define SOCK_TYPE_UDP 2
24 typedef int (* sock_op_opcl_t
)(struct socket
*);
25 typedef int (* sock_op_io_t
)(struct socket
*, struct sock_req
*, int blk
);
26 typedef int (* sock_op_select_t
)(struct socket
*, unsigned int);
27 typedef int (* sock_op_select_reply_t
)(struct socket
*);
35 sock_op_select_t select
;
36 sock_op_select_reply_t select_reply
;
44 #define SOCK_FLG_OP_PENDING 0x1
45 #define SOCK_FLG_OP_IOCTL 0x10
46 #define SOCK_FLG_OP_LISTENING 0x100 /* tcp socket is in a listening mode */
47 #define SOCK_FLG_OP_CONNECTING 0x200 /* set when waiting for a connect */
48 #define SOCK_FLG_OP_READING 0x400 /* reading operation in progress */
49 #define SOCK_FLG_OP_WRITING 0x800 /* writing operation in progress */
50 #define SOCK_FLG_CLOSED 0x1000 /* tcp socket has been closed do not
51 expect any more data */
52 /* select() flags - they say what action do we monitor */
53 #define SOCK_FLG_SEL_WRITE 0x100000
54 #define SOCK_FLG_SEL_READ 0x200000
55 #define SOCK_FLG_SEL_ERROR 0x400000
57 #define sock_select_set(sock) ((sock)->flags & (SOCK_FLG_SEL_WRITE | \
58 SOCK_FLG_SEL_READ | SOCK_FLG_SEL_ERROR))
59 #define sock_select_read_set(sock) ((sock)->flags & SOCK_FLG_SEL_READ)
60 #define sock_select_write_set(sock) ((sock)->flags & SOCK_FLG_SEL_WRITE)
61 #define sock_select_rw_set(sock) ((sock)->flags & (SOCK_FLG_SEL_READ | \
63 #define sock_select_error_set(sock) ((sock)->flags & SOCK_FLG_SEL_ERROR)
64 #define sock_clear_select(sock) do { \
65 (sock)->flags &= ~(SOCK_FLG_SEL_READ | SOCK_FLG_SEL_WRITE | \
66 SOCK_FLG_SEL_ERROR); \
79 size_t size
; /* for SOCK_REQ_READ, SOCK_REQ_WRITE */
80 unsigned long req
; /* for SOCK_REQ_IOCTL */
89 unsigned long usr_flags
;
91 struct sock_ops
* ops
;
98 struct recv_q
* recv_head
;
99 struct recv_q
* recv_tail
;
100 unsigned recv_data_size
; /* sum of data enqueued */
105 * Each component needs to provide a method how to initially open a socket.
106 * The rest is handled byt the socket library.
108 int socket_open(devminor_t minor
);
110 #define get_sock_num(x) ((long int) ((x) - socket))
111 #define is_valid_sock_num(x) (x < MAX_SOCKETS)
112 #define get_sock(x) &socket[x]
114 #define MAX_SOCKETS 255 /* FIXME as log as the sockets are identified by the
115 minor device number 255 is ok */
117 #define RESERVED (SOCK_TYPES + MAX_DEVS) /* rounded to 8 */
119 extern struct socket socket
[MAX_SOCKETS
];
121 void socket_request(message
* m
, int ipc_status
);
122 void mq_process(void);
124 struct socket
* get_unused_sock(void);
125 struct socket
* get_nic_sock(unsigned dev
);
127 void send_req_reply(struct sock_req
* req
, int status
);
129 typedef void (* recv_data_free_fn
)(void *);
131 int sock_enqueue_data(struct socket
* sock
, void * data
, unsigned size
);
132 void * sock_dequeue_data(struct socket
* sock
);
133 void sock_dequeue_data_all(struct socket
* sock
,
134 recv_data_free_fn data_free
);
136 void sock_select_notify(struct socket
* sock
);
138 static inline void * debug_malloc(size_t s
)
143 // printf("allocated %p size %d\n", ret, s);
147 #define debug_free(x) do { \
149 printf("free called from %s:%d %s freeing %p\n", __FILE__, \
150 __LINE__, __func__, (x)); \
154 int generic_op_select(struct socket
* sock
, unsigned int sel
);
155 int generic_op_select_reply(struct socket
* sock
);
157 /* a function thr user has to provide to reply to the posix server */
158 void posix_reply(endpoint_t ep
, message
* m
);
160 #endif /* __NET_SERVER_SOCKET_H__ */