KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Public Member Functions | Data Fields
fs_socket_proto 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. More...
 

Data Fields

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

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

fs_socket_proto::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

int(* fs_socket_proto::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)
int(* fs_socket_proto::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
void(* fs_socket_proto::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
int(* fs_socket_proto::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
int fs_socket_proto::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.

int(* fs_socket_proto::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).
int(* fs_socket_proto::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.
int(* fs_socket_proto::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 protcol 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
int(* fs_socket_proto::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
short(* fs_socket_proto::poll)(net_socket_t *s, short events)

Poll for events.

This function should check the given socket for any events that may have already occured 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.
int fs_socket_proto::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.

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

Recieve 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)
ssize_t(* fs_socket_proto::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)
int(* fs_socket_proto::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.
int(* fs_socket_proto::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
int(* fs_socket_proto::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
int fs_socket_proto::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: