1 #ifndef __NET_SERVER_SOCKET_H__
2 #define __NET_SERVER_SOCKET_H__
7 #include <minix/endpoint.h>
10 * User can set this variable to make the debugging output differ between
11 * various users, e.g. "TCP" or "UDP"
13 extern char * netsock_user_name
;
15 #define SOCK_TYPE_IP 0
16 #define SOCK_TYPE_TCP 1
17 #define SOCK_TYPE_UDP 2
22 typedef void (* sock_op_t
)(struct socket
*, message
*);
23 typedef void (* sock_op_io_t
)(struct socket
*, message
*, int blk
);
24 typedef int (* sock_op_open_t
)(struct socket
*, message
*);
33 sock_op_t select_reply
;
41 #define SOCK_FLG_OP_PENDING 0x1
42 #define SOCK_FLG_OP_IOCTL 0x10
43 #define SOCK_FLG_OP_LISTENING 0x100 /* tcp socket is in a listening mode */
44 #define SOCK_FLG_OP_CONNECTING 0x200 /* set when waiting for a connect */
45 #define SOCK_FLG_OP_READING 0x400 /* reading operation in progress */
46 #define SOCK_FLG_OP_WRITING 0x800 /* writing operation in progress */
47 #define SOCK_FLG_CLOSED 0x1000 /* tcp socket has been closed do not
48 expect any more data */
49 /* select() flags - they say what action do we monitor */
50 #define SOCK_FLG_SEL_WRITE 0x100000
51 #define SOCK_FLG_SEL_READ 0x200000
52 #define SOCK_FLG_SEL_ERROR 0x400000
54 #define sock_select_set(sock) ((sock)->flags & (SOCK_FLG_SEL_WRITE | \
55 SOCK_FLG_SEL_READ | SOCK_FLG_SEL_ERROR))
56 #define sock_select_read_set(sock) ((sock)->flags & SOCK_FLG_SEL_READ)
57 #define sock_select_write_set(sock) ((sock)->flags & SOCK_FLG_SEL_WRITE)
58 #define sock_select_rw_set(sock) ((sock)->flags & (SOCK_FLG_SEL_READ | \
60 #define sock_select_error_set(sock) ((sock)->flags & SOCK_FLG_SEL_ERROR)
61 #define sock_clear_select(sock) do { \
62 (sock)->flags &= ~(SOCK_FLG_SEL_READ | SOCK_FLG_SEL_WRITE | \
63 SOCK_FLG_SEL_ERROR); \
69 unsigned long usr_flags
;
71 struct sock_ops
* ops
;
74 message mess
; /* store the message which initiated the
75 last operation on this socket in case
76 we have to suspend the operation */
80 struct recv_q
* recv_head
;
81 struct recv_q
* recv_tail
;
82 unsigned recv_data_size
; /* sum of data enqueued */
87 * Each component needs to provide a method how to initially open a socket.
88 * The rest is handled byt the socket library.
90 void socket_open(message
* m
);
92 #define get_sock_num(x) ((long int) ((x) - socket))
93 #define is_valid_sock_num(x) (x < MAX_SOCKETS)
94 #define get_sock(x) &socket[x]
96 #define MAX_SOCKETS 255 /* FIXME as log as the sockets are identified by the
97 minor device number 255 is ok */
99 #define RESERVED (SOCK_TYPES + MAX_DEVS) /* rounded to 8 */
101 extern struct socket socket
[MAX_SOCKETS
];
103 void socket_request(message
* m
);
104 void mq_process(void);
107 struct socket
* get_unused_sock(void);
108 struct socket
* get_nic_sock(unsigned dev
);
110 void send_reply(message
* m
, int status
);
111 void send_reply_open(message
* m
, int status
);
112 void send_reply_close(message
* m
, int status
);
113 void sock_reply(struct socket
* sock
, int status
);
114 void sock_reply_close(struct socket
* sock
, int status
);
115 void sock_reply_select(struct socket
* sock
, unsigned selops
);
117 typedef void (* recv_data_free_fn
)(void *);
119 int sock_enqueue_data(struct socket
* sock
, void * data
, unsigned size
);
120 void * sock_dequeue_data(struct socket
* sock
);
121 void sock_dequeue_data_all(struct socket
* sock
,
122 recv_data_free_fn data_free
);
124 void sock_select_notify(struct socket
* sock
);
126 static inline void * debug_malloc(size_t s
)
131 // printf("allocated %p size %d\n", ret, s);
135 #define debug_free(x) do { \
137 printf("free called from %s:%d %s freeing %p\n", __FILE__, \
138 __LINE__, __func__, (x)); \
142 void generic_op_select(struct socket
* sock
, message
* m
);
143 void generic_op_select_reply(struct socket
* sock
, message
* m
);
145 int mq_enqueue(message
* m
);
147 /* a function thr user has to provide to reply to the posix server */
148 void posix_reply(endpoint_t ep
, message
* m
);
150 #endif /* __NET_SERVER_SOCKET_H__ */