PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
socket.c File Reference
#include "socket.h"
#include "socket_family.h"
#include <kernel/fs/ctl.h>
#include <kernel/fs/file.h>
#include <kernel/fs/mount.h>
#include <kernel/fs/path.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>
Include dependency graph for socket.c:

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, { {"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)
 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

◆ socket_data_open()

static uint64_t socket_data_open ( file_t file)
static

Definition at line 20 of file socket.c.

◆ socket_data_close()

static void socket_data_close ( file_t file)
static

Definition at line 33 of file socket.c.

◆ socket_data_read()

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

Definition at line 44 of file socket.c.

◆ socket_data_write()

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

Definition at line 70 of file socket.c.

◆ socket_data_poll()

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

Definition at line 96 of file socket.c.

◆ socket_ctl_bind()

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

Definition at line 122 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_ctl_listen()

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

Definition at line 149 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_ctl_connect()

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

Definition at line 180 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CTL_STANDARD_OPS_DEFINE()

CTL_STANDARD_OPS_DEFINE ( ctlOps  ,
{ {"bind", socket_ctl_bind, 2, 2}, {"listen", socket_ctl_listen, 1, 2}, {"connect", socket_ctl_connect, 2, 2}, {0}, }   
)
Here is the call graph for this function:

◆ socket_accept_open()

static uint64_t socket_accept_open ( file_t file)
static

Definition at line 233 of file socket.c.

Here is the call graph for this function:

◆ socket_accept_close()

static void socket_accept_close ( file_t file)
static

Definition at line 281 of file socket.c.

◆ socket_inode_cleanup()

static void socket_inode_cleanup ( inode_t inode)
static

Definition at line 300 of file socket.c.

◆ 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 318 of file socket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_unmount()

static void socket_unmount ( superblock_t superblock)
static

Definition at line 334 of file socket.c.

◆ socket_can_transition()

bool socket_can_transition ( socket_state_t  from,
socket_state_t  to 
)

Definition at line 480 of file socket.c.

Here is the caller graph for this function:

Variable Documentation

◆ dataOps

file_ops_t dataOps
static
Initial value:
= {
}
static wait_queue_t * socket_data_poll(file_t *file, poll_events_t *revents)
Definition socket.c:96
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
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.

◆ acceptOps

file_ops_t acceptOps
static
Initial value:
= {
}
static uint64_t socket_accept_open(file_t *file)
Definition socket.c:233
static void socket_accept_close(file_t *file)
Definition socket.c:281

Definition at line 292 of file socket.c.

◆ inodeOps

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

Definition at line 311 of file socket.c.

◆ superblockOps

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

Definition at line 353 of file socket.c.

◆ validTransitions

const bool validTransitions[SOCKET_STATE_AMOUNT][SOCKET_STATE_AMOUNT]
static

Definition at line 446 of file socket.c.