2006-08-08 17:07:07 +04:00
|
|
|
/*
|
2009-04-07 20:07:15 +04:00
|
|
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
2006-08-08 17:07:07 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef NET_SOCKET_H
|
|
|
|
#define NET_SOCKET_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <net_buffer.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2006-10-07 16:32:02 +04:00
|
|
|
#include <lock.h>
|
|
|
|
|
2007-10-22 00:10:43 +04:00
|
|
|
struct selectsync;
|
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
#define NET_SOCKET_MODULE_NAME "network/stack/socket/v1"
|
|
|
|
|
|
|
|
typedef struct net_socket {
|
|
|
|
struct net_protocol *first_protocol;
|
|
|
|
struct net_protocol_module_info *first_info;
|
|
|
|
|
|
|
|
int family;
|
|
|
|
int type;
|
|
|
|
int protocol;
|
|
|
|
|
|
|
|
struct sockaddr_storage address;
|
|
|
|
struct sockaddr_storage peer;
|
|
|
|
|
|
|
|
int options;
|
|
|
|
int linger;
|
2008-10-12 02:10:31 +04:00
|
|
|
int bound_to_device;
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32 buffer_size;
|
|
|
|
uint32 low_water_mark;
|
|
|
|
bigtime_t timeout;
|
|
|
|
} send, receive;
|
2006-10-07 16:32:02 +04:00
|
|
|
|
|
|
|
status_t error;
|
2006-08-08 17:07:07 +04:00
|
|
|
} net_socket;
|
|
|
|
|
|
|
|
struct net_socket_module_info {
|
|
|
|
struct module_info info;
|
|
|
|
|
2007-10-22 00:10:43 +04:00
|
|
|
status_t (*open_socket)(int family, int type, int protocol,
|
|
|
|
net_socket **_socket);
|
2006-08-08 17:07:07 +04:00
|
|
|
status_t (*close)(net_socket *socket);
|
2009-04-07 20:07:15 +04:00
|
|
|
void (*free)(net_socket *socket);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-10-22 00:10:43 +04:00
|
|
|
status_t (*readv)(net_socket *socket, const iovec *vecs,
|
|
|
|
size_t vecCount, size_t *_length);
|
|
|
|
status_t (*writev)(net_socket *socket, const iovec *vecs,
|
|
|
|
size_t vecCount, size_t *_length);
|
|
|
|
status_t (*control)(net_socket *socket, int32 op, void *data,
|
2008-04-11 20:13:47 +04:00
|
|
|
size_t length);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
ssize_t (*read_avail)(net_socket *socket);
|
|
|
|
ssize_t (*send_avail)(net_socket *socket);
|
|
|
|
|
|
|
|
status_t (*send_data)(net_socket *socket, net_buffer *buffer);
|
2007-10-22 00:10:43 +04:00
|
|
|
status_t (*receive_data)(net_socket *socket, size_t length,
|
|
|
|
uint32 flags, net_buffer **_buffer);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-04-30 23:42:12 +04:00
|
|
|
status_t (*get_option)(net_socket *socket, int level, int option,
|
|
|
|
void *value, int *_length);
|
|
|
|
status_t (*set_option)(net_socket *socket, int level, int option,
|
2007-04-20 05:58:14 +04:00
|
|
|
const void *value, int length);
|
|
|
|
|
2007-10-22 00:10:43 +04:00
|
|
|
status_t (*get_next_stat)(uint32 *cookie, int family,
|
|
|
|
struct net_stat *stat);
|
2006-12-19 05:06:07 +03:00
|
|
|
|
2006-11-09 21:53:18 +03:00
|
|
|
// connections
|
2009-04-24 14:12:30 +04:00
|
|
|
bool (*acquire_socket)(net_socket *socket);
|
2009-04-07 20:07:15 +04:00
|
|
|
bool (*release_socket)(net_socket *socket);
|
|
|
|
|
2007-10-22 00:10:43 +04:00
|
|
|
status_t (*spawn_pending_socket)(net_socket *parent,
|
|
|
|
net_socket **_socket);
|
2006-11-09 21:53:18 +03:00
|
|
|
status_t (*dequeue_connected)(net_socket *parent, net_socket **_socket);
|
2007-04-10 09:28:56 +04:00
|
|
|
ssize_t (*count_connected)(net_socket *parent);
|
2006-11-09 21:53:18 +03:00
|
|
|
status_t (*set_max_backlog)(net_socket *socket, uint32 backlog);
|
2009-04-07 20:07:15 +04:00
|
|
|
bool (*has_parent)(net_socket *socket);
|
2006-11-09 21:53:18 +03:00
|
|
|
status_t (*set_connected)(net_socket *socket);
|
2009-04-07 20:07:15 +04:00
|
|
|
status_t (*set_aborted)(net_socket *socket);
|
2006-11-09 21:53:18 +03:00
|
|
|
|
2006-10-07 16:32:02 +04:00
|
|
|
// notifications
|
2007-10-22 00:10:43 +04:00
|
|
|
status_t (*request_notification)(net_socket *socket, uint8 event,
|
2008-04-11 08:12:23 +04:00
|
|
|
struct selectsync *sync);
|
2006-10-07 16:32:02 +04:00
|
|
|
status_t (*cancel_notification)(net_socket *socket, uint8 event,
|
2007-10-22 00:10:43 +04:00
|
|
|
struct selectsync *sync);
|
2006-10-07 16:32:02 +04:00
|
|
|
status_t (*notify)(net_socket *socket, uint8 event, int32 value);
|
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
// standard socket API
|
|
|
|
int (*accept)(net_socket *socket, struct sockaddr *address,
|
|
|
|
socklen_t *_addressLength, net_socket **_acceptedSocket);
|
|
|
|
int (*bind)(net_socket *socket, const struct sockaddr *address,
|
|
|
|
socklen_t addressLength);
|
|
|
|
int (*connect)(net_socket *socket, const struct sockaddr *address,
|
|
|
|
socklen_t addressLength);
|
|
|
|
int (*getpeername)(net_socket *socket, struct sockaddr *address,
|
|
|
|
socklen_t *_addressLength);
|
|
|
|
int (*getsockname)(net_socket *socket, struct sockaddr *address,
|
|
|
|
socklen_t *_addressLength);
|
|
|
|
int (*getsockopt)(net_socket *socket, int level, int option,
|
|
|
|
void *optionValue, int *_optionLength);
|
|
|
|
int (*listen)(net_socket *socket, int backlog);
|
2007-04-05 18:26:46 +04:00
|
|
|
ssize_t (*receive)(net_socket *socket, struct msghdr *, void *data,
|
|
|
|
size_t length, int flags);
|
|
|
|
ssize_t (*send)(net_socket *socket, struct msghdr *, const void *data,
|
|
|
|
size_t length, int flags);
|
2006-08-08 17:07:07 +04:00
|
|
|
int (*setsockopt)(net_socket *socket, int level, int option,
|
|
|
|
const void *optionValue, int optionLength);
|
|
|
|
int (*shutdown)(net_socket *socket, int direction);
|
2008-04-11 08:12:23 +04:00
|
|
|
status_t (*socketpair)(int family, int type, int protocol,
|
|
|
|
net_socket* _sockets[2]);
|
2006-08-08 17:07:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NET_SOCKET_H
|