xref: /haiku/headers/private/net/net_socket.h (revision fc1ca2da5cfcb00ffdf791606d5ae97fdd58a638)
1 /*
2  * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef NET_SOCKET_H
6 #define NET_SOCKET_H
7 
8 
9 #include <net_buffer.h>
10 #include <sys/socket.h>
11 
12 #include <lock.h>
13 
14 struct selectsync;
15 
16 
17 #define NET_SOCKET_MODULE_NAME "network/stack/socket/v1"
18 
19 typedef struct net_socket {
20 	struct net_protocol		*first_protocol;
21 	struct net_protocol_module_info *first_info;
22 
23 	int						family;
24 	int						type;
25 	int						protocol;
26 
27 	struct sockaddr_storage	address;
28 	struct sockaddr_storage	peer;
29 
30 	int						options;
31 	int						linger;
32 
33 	struct {
34 		uint32		buffer_size;
35 		uint32		low_water_mark;
36 		bigtime_t	timeout;
37 	}						send, receive;
38 
39 	status_t				error;
40 	struct net_socket		*parent;
41 } net_socket;
42 
43 struct net_socket_module_info {
44 	struct module_info info;
45 
46 	status_t	(*open_socket)(int family, int type, int protocol,
47 					net_socket **_socket);
48 	status_t	(*close)(net_socket *socket);
49 	status_t	(*free)(net_socket *socket);
50 
51 	status_t	(*readv)(net_socket *socket, const iovec *vecs,
52 					size_t vecCount, size_t *_length);
53 	status_t	(*writev)(net_socket *socket, const iovec *vecs,
54 					size_t vecCount, size_t *_length);
55 	status_t	(*control)(net_socket *socket, int32 op, void *data,
56 					size_t length);
57 
58 	ssize_t		(*read_avail)(net_socket *socket);
59 	ssize_t		(*send_avail)(net_socket *socket);
60 
61 	status_t	(*send_data)(net_socket *socket, net_buffer *buffer);
62 	status_t	(*receive_data)(net_socket *socket, size_t length,
63 					uint32 flags, net_buffer **_buffer);
64 
65 	status_t	(*get_option)(net_socket *socket, int level, int option,
66 					void *value, int *_length);
67 	status_t	(*set_option)(net_socket *socket, int level, int option,
68 					const void *value, int length);
69 
70 	status_t	(*get_next_stat)(uint32 *cookie, int family,
71 					struct net_stat *stat);
72 
73 	// connections
74 	status_t	(*spawn_pending_socket)(net_socket *parent,
75 					net_socket **_socket);
76 	void		(*delete_socket)(net_socket *socket);
77 	status_t	(*dequeue_connected)(net_socket *parent, net_socket **_socket);
78 	ssize_t		(*count_connected)(net_socket *parent);
79 	status_t	(*set_max_backlog)(net_socket *socket, uint32 backlog);
80 	status_t	(*set_connected)(net_socket *socket);
81 
82 	// notifications
83 	status_t	(*request_notification)(net_socket *socket, uint8 event,
84 					struct selectsync *sync);
85 	status_t	(*cancel_notification)(net_socket *socket, uint8 event,
86 					struct selectsync *sync);
87 	status_t	(*notify)(net_socket *socket, uint8 event, int32 value);
88 
89 	// standard socket API
90 	int			(*accept)(net_socket *socket, struct sockaddr *address,
91 					socklen_t *_addressLength, net_socket **_acceptedSocket);
92 	int			(*bind)(net_socket *socket, const struct sockaddr *address,
93 					socklen_t addressLength);
94 	int			(*connect)(net_socket *socket, const struct sockaddr *address,
95 					socklen_t addressLength);
96 	int			(*getpeername)(net_socket *socket, struct sockaddr *address,
97 					socklen_t *_addressLength);
98 	int			(*getsockname)(net_socket *socket, struct sockaddr *address,
99 					socklen_t *_addressLength);
100 	int			(*getsockopt)(net_socket *socket, int level, int option,
101 					void *optionValue, int *_optionLength);
102 	int			(*listen)(net_socket *socket, int backlog);
103 	ssize_t		(*receive)(net_socket *socket, struct msghdr *, void *data,
104 					size_t length, int flags);
105 	ssize_t		(*send)(net_socket *socket, struct msghdr *, const void *data,
106 					size_t length, int flags);
107 	int			(*setsockopt)(net_socket *socket, int level, int option,
108 					const void *optionValue, int optionLength);
109 	int			(*shutdown)(net_socket *socket, int direction);
110 	status_t	(*socketpair)(int family, int type, int protocol,
111 					net_socket* _sockets[2]);
112 };
113 
114 #endif	// NET_SOCKET_H
115