KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
fs_socket_proto_t Struct Reference

Internal sockets protocol handler. More...

#include <kos/fs_socket.h>

Public Member Functions

 TAILQ_ENTRY (fs_socket_proto) entry
 Entry into the global list of protocols.
 

Data Fields

int domain
 Domain of support for this protocol handler.
 
int type
 Type of support for this protocol handler.
 
int protocol
 Protocol of support for this protocol handler.
 
int(* socket )(net_socket_t *s, int domain, int type, int protocol)
 Create a new socket for the protocol.
 
void(* close )(net_socket_t *hnd)
 Close a socket that was created with the protocol.
 
int(* accept )(net_socket_t *s, struct sockaddr *addr, socklen_t *alen)
 Accept a connection on a socket created with the protocol.
 
int(* bind )(net_socket_t *s, const struct sockaddr *addr, socklen_t alen)
 Bind a socket created with the protocol to an address.
 
int(* connect )(net_socket_t *s, const struct sockaddr *addr, socklen_t alen)
 Connect a socket created with the protocol to a remote system.
 
int(* listen )(net_socket_t *s, int backlog)
 Listen for incoming connections on a socket created with the protocol.
 
ssize_t(* recvfrom )(net_socket_t *s, void *buffer, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
 Receive data on a socket created with the protocol.
 
ssize_t(* sendto )(net_socket_t *s, const void *msg, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
 Send data on a socket created with the protocol.
 
int(* shutdownsock )(net_socket_t *s, int how)
 Shut down a socket created with the protocol.
 
int(* input )(netif_t *src, int domain, const void *hdr, const uint8 *data, size_t size)
 Input a packet into a protocol.
 
int(* getsockopt )(net_socket_t *s, int level, int option_name, void *option_value, socklen_t *option_len)
 Get socket options.
 
int(* setsockopt )(net_socket_t *s, int level, int option_name, const void *option_value, socklen_t option_len)
 Set socket options.
 
int(* getsockname )(net_socket_t *s, struct sockaddr *name, socklen_t *name_len)
 Get socket name.
 
int(* getpeername )(net_socket_t *s, struct sockaddr *name, socklen_t *name_len)
 Get the name of the peer connected to a socket created with the protocol.
 
int(* fcntl )(net_socket_t *s, int cmd, va_list ap)
 Manipulate file options.
 
short(* poll )(net_socket_t *s, short events)
 Poll for events.
 

Detailed Description

Internal sockets protocol handler.

This structure is a protocol handler used within fs_socket. Each protocol that is supported has one of these registered for it within the kernel. Generally, users will not come in contact with this structure (unless you're planning on writing a protocol handler), and it can generally be ignored.

For a complete list of appropriate errno values to return from any functions that are in here, take a look at the Single Unix Specification (aka, the POSIX spec), specifically the page about sys/socket.h (and all the functions that it defines, which is available at http://www.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html .

Member Function Documentation

◆ TAILQ_ENTRY()

fs_socket_proto_t::TAILQ_ENTRY ( fs_socket_proto )

Entry into the global list of protocols.

Contrary to what Doxygen might think, this is NOT a function. This should be initialized with the FS_SOCKET_PROTO_ENTRY macro before adding the protocol to the kernel with fs_socket_proto_add().

Field Documentation

◆ accept

int(* fs_socket_proto_t::accept) (net_socket_t *s, struct sockaddr *addr, socklen_t *alen)

Accept a connection on a socket created with the protocol.

This function should implement the accept() system call for the protocol. The semantics are exactly as expected for that function.

Parameters
sThe socket to accept a connection on
addrThe address of the incoming connection
alenThe length of the address
Returns
A newly created socket for the incoming connection or -1 on error (with errno set appropriately)

◆ bind

int(* fs_socket_proto_t::bind) (net_socket_t *s, const struct sockaddr *addr, socklen_t alen)

Bind a socket created with the protocol to an address.

This function should implement the bind() system call for the protocol. The semantics are exactly as expected for that function.

Parameters
sThe socket to bind to the address
addrThe address to bind to
alenThe length of the address
Return values
-1On error (set errno appropriately)
0On success

◆ close

void(* fs_socket_proto_t::close) (net_socket_t *hnd)

Close a socket that was created with the protocol.

This function must do any work required to close a socket and destroy it. This function will be called when a socket requests to be closed with the close system call. There are no errors defined for this function.

Parameters
sThe socket to close

◆ connect

int(* fs_socket_proto_t::connect) (net_socket_t *s, const struct sockaddr *addr, socklen_t alen)

Connect a socket created with the protocol to a remote system.

This function should implement the connect() system call for the protocol. The semantics are exactly as expected for that function.

Parameters
sThe socket to connect with
addrThe address to connect to
alenThe length of the address
Return values
-1On error (with errno set appropriately)
0On success

◆ domain

int fs_socket_proto_t::domain

Domain of support for this protocol handler.

This field determines which sockets domain this protocol handler actually supports. This corresponds with the domain argument of the socket() function.

◆ fcntl

int(* fs_socket_proto_t::fcntl) (net_socket_t *s, int cmd, va_list ap)

Manipulate file options.

This function should implement the fcntl() system call for the given protocol. The semantics are exactly as defined for that function.

Parameters
sThe socket to manipulate.
cmdThe fcntl command to run.
apArguments to the command.
Return values
-1On error (generally, set errno appropriately).

◆ getpeername

int(* fs_socket_proto_t::getpeername) (net_socket_t *s, struct sockaddr *name, socklen_t *name_len)

Get the name of the peer connected to a socket created with the protocol.

This function should implement the getpeername() system call for the protocol. The semantics are exactly as expected for that function.

Parameters
sThe socket from which to get the peer address.
namePointer to a sockaddr structure which will hold the resulting address information.
name_lenThe amount of space pointed to by name, in bytes. On return, this is set to the actual size of the returned address information.
Return values
-1On error (with errno set appropriately).
0On success.

◆ getsockname

int(* fs_socket_proto_t::getsockname) (net_socket_t *s, struct sockaddr *name, socklen_t *name_len)

Get socket name.

This function should implement the getsockname() system call for the given protocol. The semantics are exactly as defined for that function.

Currently all options (regardless of level) are passed onto the protocol handler.

Parameters
sThe socket to get the name of.
namePointer to a sockaddr structure which will hold the resulting address information.
name_lenThe amount of space pointed to by name, in bytes. On return, this is set to the actual size of the returned address information.
Return values
-1On error (with errno set appropriately).
0On success.

◆ getsockopt

int(* fs_socket_proto_t::getsockopt) (net_socket_t *s, int level, int option_name, void *option_value, socklen_t *option_len)

Get socket options.

This function should implement the getsockopt() system call for the given protocol. The semantics are exactly as defined for that function.

Currently all options (regardless of level) are passed onto the protocol handler.

Parameters
sThe socket to get options for.
levelThe protocol level to get options at.
option_nameThe option to look up.
option_valueStorage for the value of the option.
option_lenThe length of option_value on call, and the real option length (if less than the original value) on return.
Return values
-1On error (set errno appropriately).
0On success.

◆ input

int(* fs_socket_proto_t::input) (netif_t *src, int domain, const void *hdr, const uint8 *data, size_t size)

Input a packet into a protocol.

This function should read in the packet specified by the arguments and sort out what exactly to do with it. This usually involves checking if there is an open socket with the source address and adding it to a packet queue if there is.

Parameters
srcThe interface the packet was input on
domainThe low-level protocol used (AF_INET or AF_INET6)
hdrThe low-level protocol header
dataThe packet itself, including any protocol headers, but not any from lower-level protocols
sizeThe size of the packet, not including any lower- level protocol headers
Return values
-1On error (the packet is discarded)
0On success

◆ listen

int(* fs_socket_proto_t::listen) (net_socket_t *s, int backlog)

Listen for incoming connections on a socket created with the protocol.

This function should implement the listen() system call for the protocol. The semantics are exactly as expected for that function.

Parameters
sThe socket to listen on
backlogThe number of connections to queue
Return values
-1On error (with errno set appropriately)
0On success

◆ poll

short(* fs_socket_proto_t::poll) (net_socket_t *s, short events)

Poll for events.

This function should check the given socket for any events that may have already occurred that are specified. This is used to back the poll() system call. This function should not block to wait for any events. This function may be called in an interrupt.

Parameters
sThe socket to poll.
eventsThe events to check for.
Return values
Amask of any of the events specified that are currently true in the socket. 0 if none are true.

◆ protocol

int fs_socket_proto_t::protocol

Protocol of support for this protocol handler.

This field determines the protocol that this protocol handler actually pays attention to. This corresponds with the protocol argument of the socket() function.

◆ recvfrom

ssize_t(* fs_socket_proto_t::recvfrom) (net_socket_t *s, void *buffer, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)

Receive data on a socket created with the protocol.

This function should implement the recvfrom() system call for the protocol. The semantics are exactly as expected for that function. Also, this function should implement the recv() system call, which will call this function with NULL for addr and alen.

Parameters
sThe socket to receive data on
bufferThe buffer to save data in
lenThe length of the buffer
flagsFlags to the function
addrSpace to store the address that data came from (NULL if this was called by recv())
alenSpace to store the length of the address (NULL if this was called by recv())
Return values
-1On error (set errno appropriately)
0No outstanding data and the peer has disconnected cleanly
nThe number of bytes received (may be less than len)

◆ sendto

ssize_t(* fs_socket_proto_t::sendto) (net_socket_t *s, const void *msg, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)

Send data on a socket created with the protocol.

This function should implement the sendto() system call for the protocol. The semantics are exactly as expected for that function. Also, this function should implement the send() system call, which will call this function with NULL for addr and 0 for alen.

Parameters
sThe socket to send data on
msgThe data to send
lenThe length of data to send
flagsFlags to the function
addrThe address to send data to (NULL if this was called by send())
alenThe length of the address (0 if this was called by send())
Return values
-1On error (set errno appropriately)
nThe number of bytes actually sent (may be less than len)

◆ setsockopt

int(* fs_socket_proto_t::setsockopt) (net_socket_t *s, int level, int option_name, const void *option_value, socklen_t option_len)

Set socket options.

This function should implement the setsockopt() system call for the given protocol. The semantics are exactly as defined for that function.

Currently all options (regardless of level) are passed onto the protocol handler.

Parameters
sThe socket to set options for.
levelThe protocol level to set options at.
option_nameThe option to set.
option_valueThe value to set for the option.
option_lenThe length of the option_value value.
Return values
-1On error (set errno appropriately).
0On success.

◆ shutdownsock

int(* fs_socket_proto_t::shutdownsock) (net_socket_t *s, int how)

Shut down a socket created with the protocol.

This function should implement the shutdown() system call for the protocol. The semantics are exactly as expected for that function.

Parameters
sThe socket to shut down
howWhat should be shut down on the socket
Return values
-1On error (set errno appropriately)
0On success

◆ socket

int(* fs_socket_proto_t::socket) (net_socket_t *s, int domain, int type, int protocol)

Create a new socket for the protocol.

This function must create a new socket, initializing any data that the protocol might need for the socket, based on the parameters passed in. The socket passed in is already initialized prior to the handler being called, and will be cleaned up by fs_socket if an error is returned from the handler (a return value of -1).

Parameters
sThe socket structure to initialize
domainDomain of the socket
typeType of the socket
protocolProtocol of the socket
Return values
-1On error (errno should be set appropriately)
0On success

◆ type

int fs_socket_proto_t::type

Type of support for this protocol handler.

This field determines which types of sockets that this protocol handler pays attention to. This corresponds with the type argument of the socket() function.


The documentation for this struct was generated from the following file: