2006-08-08 17:07:07 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
|
|
|
* 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 <Select.h>
|
|
|
|
#include <lock.h>
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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-12-19 06:01:18 +03:00
|
|
|
struct net_socket *parent;
|
2006-08-08 17:07:07 +04:00
|
|
|
} net_socket;
|
|
|
|
|
|
|
|
struct net_socket_module_info {
|
|
|
|
struct module_info info;
|
|
|
|
|
2006-11-11 14:56:52 +03: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);
|
|
|
|
status_t (*free)(net_socket *socket);
|
|
|
|
|
|
|
|
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, size_t length);
|
|
|
|
|
|
|
|
ssize_t (*read_avail)(net_socket *socket);
|
|
|
|
ssize_t (*send_avail)(net_socket *socket);
|
|
|
|
|
|
|
|
status_t (*send_data)(net_socket *socket, net_buffer *buffer);
|
|
|
|
status_t (*receive_data)(net_socket *socket, size_t length, uint32 flags,
|
|
|
|
net_buffer **_buffer);
|
|
|
|
|
2007-04-20 05:58:14 +04:00
|
|
|
status_t (*get_option)(net_socket *socket, int option, void *value,
|
|
|
|
int *_length);
|
|
|
|
status_t (*set_option)(net_socket *socket, int option,
|
|
|
|
const void *value, int length);
|
|
|
|
|
2006-12-19 05:06:07 +03:00
|
|
|
status_t (*get_next_stat)(uint32 *cookie, int family, struct net_stat *stat);
|
|
|
|
|
2006-11-09 21:53:18 +03:00
|
|
|
// connections
|
|
|
|
status_t (*spawn_pending_socket)(net_socket *parent, net_socket **_socket);
|
|
|
|
void (*delete_socket)(net_socket *socket);
|
|
|
|
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);
|
|
|
|
status_t (*set_connected)(net_socket *socket);
|
|
|
|
|
2006-10-07 16:32:02 +04:00
|
|
|
// notifications
|
|
|
|
status_t (*request_notification)(net_socket *socket, uint8 event, uint32 ref,
|
|
|
|
selectsync *sync);
|
|
|
|
status_t (*cancel_notification)(net_socket *socket, uint8 event,
|
|
|
|
selectsync *sync);
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NET_SOCKET_H
|