KallistiOS git master
Independent SDK for the Sega Dreamcast
|
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. | |
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 .
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().
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.
s | The socket to accept a connection on |
addr | The address of the incoming connection |
alen | The length of the address |
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.
s | The socket to bind to the address |
addr | The address to bind to |
alen | The length of the address |
-1 | On error (set errno appropriately) |
0 | On success |
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.
s | The socket to close |
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.
s | The socket to connect with |
addr | The address to connect to |
alen | The length of the address |
-1 | On error (with errno set appropriately) |
0 | On success |
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.
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.
s | The socket to manipulate. |
cmd | The fcntl command to run. |
ap | Arguments to the command. |
-1 | On error (generally, set errno appropriately). |
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.
s | The socket from which to get the peer address. |
name | Pointer to a sockaddr structure which will hold the resulting address information. |
name_len | The amount of space pointed to by name, in bytes. On return, this is set to the actual size of the returned address information. |
-1 | On error (with errno set appropriately). |
0 | On success. |
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.
s | The socket to get the name of. |
name | Pointer to a sockaddr structure which will hold the resulting address information. |
name_len | The amount of space pointed to by name, in bytes. On return, this is set to the actual size of the returned address information. |
-1 | On error (with errno set appropriately). |
0 | On success. |
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.
s | The socket to get options for. |
level | The protocol level to get options at. |
option_name | The option to look up. |
option_value | Storage for the value of the option. |
option_len | The length of option_value on call, and the real option length (if less than the original value) on return. |
-1 | On error (set errno appropriately). |
0 | On success. |
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.
src | The interface the packet was input on |
domain | The low-level protocol used (AF_INET or AF_INET6) |
hdr | The low-level protocol header |
data | The packet itself, including any protocol headers, but not any from lower-level protocols |
size | The size of the packet, not including any lower- level protocol headers |
-1 | On error (the packet is discarded) |
0 | On success |
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.
s | The socket to listen on |
backlog | The number of connections to queue |
-1 | On error (with errno set appropriately) |
0 | On success |
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.
s | The socket to poll. |
events | The events to check for. |
A | mask of any of the events specified that are currently true in the socket. 0 if none are true. |
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.
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.
s | The socket to receive data on |
buffer | The buffer to save data in |
len | The length of the buffer |
flags | Flags to the function |
addr | Space to store the address that data came from (NULL if this was called by recv()) |
alen | Space to store the length of the address (NULL if this was called by recv()) |
-1 | On error (set errno appropriately) |
0 | No outstanding data and the peer has disconnected cleanly |
n | The number of bytes received (may be less than len) |
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.
s | The socket to send data on |
msg | The data to send |
len | The length of data to send |
flags | Flags to the function |
addr | The address to send data to (NULL if this was called by send()) |
alen | The length of the address (0 if this was called by send()) |
-1 | On error (set errno appropriately) |
n | The number of bytes actually sent (may be less than len) |
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.
s | The socket to set options for. |
level | The protocol level to set options at. |
option_name | The option to set. |
option_value | The value to set for the option. |
option_len | The length of the option_value value. |
-1 | On error (set errno appropriately). |
0 | On success. |
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.
s | The socket to shut down |
how | What should be shut down on the socket |
-1 | On error (set errno appropriately) |
0 | On success |
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).
s | The socket structure to initialize |
domain | Domain of the socket |
type | Type of the socket |
protocol | Protocol of the socket |
-1 | On error (errno should be set appropriately) |
0 | On success |
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.