PatchworkOS
Loading...
Searching...
No Matches
socket.c File Reference
#include <kernel/net/socket.h>
#include <kernel/fs/ctl.h>
#include <kernel/fs/file.h>
#include <kernel/fs/mount.h>
#include <kernel/fs/path.h>
#include <kernel/net/socket_family.h>
#include <kernel/proc/process.h>
#include <kernel/sched/sched.h>
#include <kernel/sched/wait.h>
#include <kernel/sync/lock.h>
#include <kernel/sync/mutex.h>
#include <kernel/sync/rwmutex.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>

Go to the source code of this file.

Functions

static uint64_t socket_data_open (file_t *file)
 
static void socket_data_close (file_t *file)
 
static uint64_t socket_data_read (file_t *file, void *buf, size_t count, uint64_t *offset)
 
static uint64_t socket_data_write (file_t *file, const void *buf, size_t count, uint64_t *offset)
 
static wait_queue_tsocket_data_poll (file_t *file, poll_events_t *revents)
 
static uint64_t socket_ctl_bind (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t socket_ctl_listen (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t socket_ctl_connect (file_t *file, uint64_t argc, const char **argv)
 
 CTL_STANDARD_OPS_DEFINE (ctlOps,(ctl_array_t){ {"bind", socket_ctl_bind, 2, 2}, {"listen", socket_ctl_listen, 1, 2}, {"connect", socket_ctl_connect, 2, 2}, {0}, })
 
static uint64_t socket_accept_open (file_t *file)
 
static void socket_accept_close (file_t *file)
 
static void socket_inode_cleanup (inode_t *inode)
 
static void socket_free (socket_t *sock)
 
static void socket_unmount (superblock_t *superblock)
 
socket_tsocket_new (socket_family_t *family, socket_type_t type, path_flags_t flags)
 Create a new socket.
 
bool socket_can_transition (socket_state_t from, socket_state_t to)
 
uint64_t socket_start_transition (socket_t *sock, socket_state_t state)
 Starts a socket state transition.
 
void socket_continue_transition (socket_t *sock, socket_state_t state)
 Without releasing the socket mutex, start a transition to a new target state.
 
void socket_end_transition (socket_t *sock, uint64_t result)
 Ends a socket state transition.
 

Variables

static file_ops_t dataOps
 
static file_ops_t acceptOps
 
static inode_ops_t inodeOps
 
static superblock_ops_t superblockOps
 
static const bool validTransitions [SOCKET_STATE_AMOUNT][SOCKET_STATE_AMOUNT]
 

Function Documentation

◆ CTL_STANDARD_OPS_DEFINE()

CTL_STANDARD_OPS_DEFINE ( ctlOps  ,
(ctl_array_t){ {"bind", socket_ctl_bind, 2, 2}, {"listen", socket_ctl_listen, 1, 2}, {"connect", socket_ctl_connect, 2, 2}, {0}, }   
)

◆ socket_accept_close()

static void socket_accept_close ( file_t file)
static

Definition at line 283 of file socket.c.

References DEREF, file, NULL, and dentry_t::private.

◆ socket_accept_open()

◆ socket_can_transition()

bool socket_can_transition ( socket_state_t  from,
socket_state_t  to 
)

Definition at line 482 of file socket.c.

References SOCKET_STATE_AMOUNT, and validTransitions.

Referenced by socket_continue_transition(), and socket_start_transition().

◆ socket_ctl_bind()

static uint64_t socket_ctl_bind ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

◆ socket_ctl_connect()

◆ socket_ctl_listen()

static uint64_t socket_ctl_listen ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

◆ socket_data_close()

static void socket_data_close ( file_t file)
static

Definition at line 33 of file socket.c.

References DEREF, file, NULL, and dentry_t::private.

◆ socket_data_open()

static uint64_t socket_data_open ( file_t file)
static

Definition at line 20 of file socket.c.

References EINVAL, ERR, errno, socket_t::family, file, dentry_t::inode, NULL, dentry_t::private, inode_t::private, and REF.

◆ socket_data_poll()

static wait_queue_t * socket_data_poll ( file_t file,
poll_events_t revents 
)
static

◆ socket_data_read()

static uint64_t socket_data_read ( file_t file,
void *  buf,
size_t  count,
uint64_t offset 
)
static

◆ socket_data_write()

static uint64_t socket_data_write ( file_t file,
const void *  buf,
size_t  count,
uint64_t offset 
)
static

◆ socket_free()

static void socket_free ( socket_t sock)
static

Will only be called when the socket reference count reaches 0. Meaning the socket must be unmounted first.

Definition at line 320 of file socket.c.

References socket_family_ops_t::deinit, socket_t::family, free(), socket_t::mutex, NULL, socket_family_t::ops, and rwmutex_deinit().

Referenced by socket_new().

◆ socket_inode_cleanup()

static void socket_inode_cleanup ( inode_t inode)
static

Definition at line 302 of file socket.c.

References DEREF, NULL, and inode_t::private.

◆ socket_unmount()

static void socket_unmount ( superblock_t superblock)
static

Variable Documentation

◆ acceptOps

file_ops_t acceptOps
static
Initial value:
= {
}
static uint64_t socket_accept_open(file_t *file)
Definition socket.c:235
static wait_queue_t * socket_data_poll(file_t *file, poll_events_t *revents)
Definition socket.c:96
static void socket_accept_close(file_t *file)
Definition socket.c:283
static uint64_t socket_data_write(file_t *file, const void *buf, size_t count, uint64_t *offset)
Definition socket.c:70
static uint64_t socket_data_read(file_t *file, void *buf, size_t count, uint64_t *offset)
Definition socket.c:44

Definition at line 294 of file socket.c.

Referenced by socket_new().

◆ dataOps

file_ops_t dataOps
static
Initial value:
= {
}
static void socket_data_close(file_t *file)
Definition socket.c:33
static uint64_t socket_data_open(file_t *file)
Definition socket.c:20

Definition at line 114 of file socket.c.

Referenced by socket_new().

◆ inodeOps

inode_ops_t inodeOps
static
Initial value:
= {
}
static void socket_inode_cleanup(inode_t *inode)
Definition socket.c:302

Definition at line 313 of file socket.c.

Referenced by socket_new().

◆ superblockOps

superblock_ops_t superblockOps
static
Initial value:
= {
.unmount = socket_unmount,
}
static void socket_unmount(superblock_t *superblock)
Definition socket.c:336

Definition at line 355 of file socket.c.

Referenced by socket_new(), sysfs_mount(), and sysfs_mount_new().

◆ validTransitions

const bool validTransitions[SOCKET_STATE_AMOUNT][SOCKET_STATE_AMOUNT]
static

Definition at line 448 of file socket.c.

Referenced by socket_can_transition().