KallistiOS
##version##
|
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... | |
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::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::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::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::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::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::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.
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::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::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 protcol 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::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::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.
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::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.
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::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::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::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::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::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.