10#ifndef KERNEL_SOCKET_H
11#define KERNEL_SOCKET_H
13#include <kernel/net.h>
14#include <kernel/spinlock.h>
18#include <utils/container_of.h>
31 const struct socket_protocol *
proto;
42 return socket_type == SOCK_STREAM;
126struct socket_protocol_ops {
128 error_t (*init)(
struct socket *);
130 error_t (*bind)(
struct socket *,
struct sockaddr *addr, socklen_t addrlen);
132 error_t (*connect)(
struct socket *,
struct sockaddr *addr,
135 ssize_t (*sendmsg)(
struct socket *,
const struct msghdr *,
int flags);
137 ssize_t (*recvmsg)(
struct socket *,
struct msghdr *,
int flags);
141struct socket_protocol {
143 enum socket_type type;
144 const struct socket_protocol_ops *ops;
static ALWAYS_INLINE void spinlock_release(spinlock_t *lock)
Release a spinlock for others to take it.
Definition: spinlock.h:90
socket_state
Socket connection state.
Definition: socket.h:23
struct socket * socket_alloc(void)
Allocate and initialize a new socket.
Definition: socket.c:33
error_t socket_domain_register(struct socket_domain *)
Register a new domain of sockets.
Definition: socket.c:17
static struct socket * socket_from_vnode(struct vnode *vnode)
Definition: socket.h:69
static bool socket_mode_is_connection(enum socket_type socket_type)
Check whether the socket is connection oriented (TCP, ...)
Definition: socket.h:40
error_t socket_enqueue_packet(struct socket *socket, struct packet *packet)
Place a packet inside the socket's receive queue.
Definition: socket.c:46
error_t socket_init(struct socket *socket, int domain, int type, int proto)
Initialize a socket's underlying protocol.
Definition: socket.c:26
struct packet * socket_dequeue_packet(struct socket *socket)
Retreive one packet from the socket's receive queue.
Definition: socket.c:55
@ SOCKET_DISCONNECTED
Definition: socket.h:24
@ SOCKET_CONNECTED
Definition: socket.h:25
#define container_of(_ptr, _struct, _field)
Cast a member of a structure out to the containing structure.
Definition: container_of.h:12
Opened file description.
Definition: file.h:29
The head of a doubly linked list.
Definition: linked_list.h:43
Intrusive doubly-linked list node.
Definition: linked_list.h:27
A network packet.
Definition: packet.h:51
Socket communication domain.
Definition: socket.h:113
error_t(* socket_init)(struct socket *, int type, int proto)
Match socket with its protocol, and initialize necessary per-domain data.
Definition: socket.h:119
enum communication_domain domain
Definition: socket.h:114
Socket node.
Definition: socket.h:63
struct vnode vnode
Definition: socket.h:65
struct socket socket
Definition: socket.h:64
A BSD socket.
Definition: socket.h:29
queue_t rx_packets
Definition: socket.h:35
enum socket_state state
Definition: socket.h:32
spinlock_t lock
Definition: socket.h:33
const struct socket_protocol * proto
Definition: socket.h:31
void * data
Definition: socket.h:34
struct file * file
Definition: socket.h:30
spinlock_t rx_lock
Definition: socket.h:36
Spinlock.
Definition: spinlock.h:29
represents a single virtual node
Definition: vfs.h:205