|
AquilaOS documentation
How it works, and its code
|
Sockets: what every domain's sockets share. More...
#include <core/system.h>#include <core/string.h>#include <ds/queue.h>#include <aquila/errno.h>#include <net/socket.h>#include <aquila/fcntl.h>Go to the source code of this file.
Functions | |
| int | socket_create (struct file *file, int domain, int type, int protocol) |
| Makes a socket of a domain in an open file, for socket(). | |
| int | socket_accept (struct file *file, struct file *conn, const struct sockaddr *addr, socklen_t *len) |
| Accepts a connection on a listening socket, for accept(). | |
| int | socket_bind (struct file *file, const struct sockaddr *addr, socklen_t len) |
| Gives a socket its local address, for bind(). | |
| int | socket_connect (struct file *file, const struct sockaddr *addr, socklen_t len) |
| Connects a socket to a peer, for connect(). | |
| int | socket_listen (struct file *file, int backlog) |
| Makes a socket listen for connections, for listen(). | |
| ssize_t | socket_send (struct file *file, struct iobuf *io, int flags, const struct sockaddr *to, socklen_t tolen) |
| Sends data on a socket, for send(), sendto() and write(). | |
| ssize_t | socket_recv (struct file *file, struct iobuf *io, int flags, struct sockaddr *from, socklen_t *fromlen) |
| Receives data from a socket, for recv(), recvfrom() and read(). | |
| int | socket_can_read (struct file *file, size_t len) |
| Says whether a socket has something to read, for select() and poll(). | |
| struct waitq * | socket_wait_queue (struct file *file, int write) |
| Finds the wait queue that a socket's readers (or writers) sleep on, for select() and poll() to register. | |
| int | socket_can_write (struct file *file, size_t len) |
| Says whether a socket has room to write, for select() and poll(). | |
| int | socket_shutdown_dir (struct file *file, int how) |
| Shuts down reading, writing or both on a socket, for shutdown(). | |
| int | socket_shutdown (struct file *file, int how) |
| Releases a socket when its open file is closed (its last descriptor went). | |
| int | socket_getname (struct file *file, struct sockaddr *addr, socklen_t *len, int peer) |
| Gets a socket's local address, or its peer's, for getsockname() and getpeername(). | |
| static int | sockopt_int (void *val, socklen_t *len, int v) |
| Sets an option's value to the int v. | |
| int | socket_getsockopt (struct file *file, int level, int name, void *val, socklen_t *len) |
| Reads a socket option, for getsockopt(). | |
| int | socket_setsockopt (struct file *file, int level, int name, const void *val, socklen_t len) |
| Sets a socket option, for setsockopt(). | |
| int | socket_ioctl (struct file *file, int request, void *argp) |
| Handles an ioctl() on a socket, by passing it to the protocol. | |
Sockets: what every domain's sockets share.
A socket is an open file with FILE_SOCKET set. The system calls on sockets come here, which checks that the file is one, then passes the call to its domain's operations (struct sock_ops): Unix sockets (net/unix/unix.c) or Internet ones (net/inet/socket.c).
Definition in file socket.c.
| int socket_accept | ( | struct file * | file, |
| struct file * | conn, | ||
| const struct sockaddr * | addr, | ||
| socklen_t * | len ) |
Accepts a connection on a listening socket, for accept().
| file | the listening socket |
| conn | the open file that becomes the connection's socket |
| addr | where to put the peer's address, in user memory, or NULL |
| len | its size, in user memory |
Definition at line 59 of file socket.c.
References FILE_SOCKET, file::flags, and socket_accept().
Referenced by socket_accept(), and sys_accept().
| int socket_bind | ( | struct file * | file, |
| const struct sockaddr * | addr, | ||
| socklen_t | len ) |
Gives a socket its local address, for bind().
| file | the socket |
| addr | the address, in the kernel's memory |
| len | its size |
Definition at line 83 of file socket.c.
References FILE_SOCKET, file::flags, and socket_bind().
Referenced by socket_bind(), and sys_bind().
Says whether a socket has something to read, for select() and poll().
| file | the socket |
| len | how much a read would want |
Definition at line 189 of file socket.c.
References FILE_SOCKET, file::flags, and socket_can_read().
Referenced by socket_can_read(), and vfs_file_can_read().
Says whether a socket has room to write, for select() and poll().
| file | the socket |
| len | how much a write would want |
Definition at line 225 of file socket.c.
References FILE_SOCKET, file::flags, and socket_can_write().
Referenced by socket_can_write(), and vfs_file_can_write().
| int socket_connect | ( | struct file * | file, |
| const struct sockaddr * | addr, | ||
| socklen_t | len ) |
Connects a socket to a peer, for connect().
| file | the socket |
| addr | the peer's address, in the kernel's memory |
| len | its size |
Definition at line 102 of file socket.c.
References FILE_SOCKET, file::flags, and socket_connect().
Referenced by socket_connect(), and sys_connect().
| int socket_create | ( | struct file * | file, |
| int | domain, | ||
| int | type, | ||
| int | protocol ) |
Makes a socket of a domain in an open file, for socket().
| file | the open file that becomes the socket |
| domain | AF_UNIX or AF_INET |
| type | the socket's type (SOCK_STREAM, SOCK_DGRAM) |
| protocol | the protocol, or 0 for the type's default |
Definition at line 27 of file socket.c.
References file::flags, socket_create(), socket_inet_create(), and socket_unix_create().
Referenced by socket_create(), and sys_socket().
| int socket_getname | ( | struct file * | file, |
| struct sockaddr * | addr, | ||
| socklen_t * | len, | ||
| int | peer ) |
Gets a socket's local address, or its peer's, for getsockname() and getpeername().
| file | the socket |
| addr | where to put the address, in the kernel's memory |
| len | its size, set to the address's |
| peer | 0 for the local address, 1 for the peer's |
Definition at line 289 of file socket.c.
References FILE_SOCKET, file::flags, and socket_getname().
Referenced by socket_getname(), and socket_name().
| int socket_getsockopt | ( | struct file * | file, |
| int | level, | ||
| int | name, | ||
| void * | val, | ||
| socklen_t * | len ) |
Reads a socket option, for getsockopt().
The protocol is asked first; SO_TYPE, and SO_ERROR for a protocol that keeps no errors, are answered here.
| file | the socket |
| level | SOL_SOCKET, or a protocol's level |
| name | the option |
| val | where to put its value, in the kernel's memory |
| len | its size, set to the value's |
Definition at line 325 of file socket.c.
References FILE_SOCKET, file::flags, sock_ops::getsockopt, socket_getsockopt(), and sockopt_int().
Referenced by socket_getsockopt(), and sys_getsockopt().
| int socket_ioctl | ( | struct file * | file, |
| int | request, | ||
| void * | argp ) |
Handles an ioctl() on a socket, by passing it to the protocol.
| file | the socket |
| request | the request |
| argp | its argument, in user memory |
Definition at line 399 of file socket.c.
References FILE_SOCKET, file::flags, and socket_ioctl().
Referenced by socket_ioctl(), and sys_ioctl().
| int socket_listen | ( | struct file * | file, |
| int | backlog ) |
Makes a socket listen for connections, for listen().
| file | the socket |
| backlog | how many connections may wait to be accepted |
Definition at line 120 of file socket.c.
References FILE_SOCKET, file::flags, and socket_listen().
Referenced by socket_listen(), and sys_listen().
| ssize_t socket_recv | ( | struct file * | file, |
| struct iobuf * | io, | ||
| int | flags, | ||
| struct sockaddr * | from, | ||
| socklen_t * | fromlen ) |
Receives data from a socket, for recv(), recvfrom() and read().
| file | the socket |
| io | where to put the data, in user memory |
| flags | MSG_* flags |
| from | where to put the sender's address, or NULL |
| fromlen | its size |
Definition at line 169 of file socket.c.
References FILE_SOCKET, file::flags, and socket_recv().
Referenced by socket_recv(), sys_recv(), and vfs_file_read().
| ssize_t socket_send | ( | struct file * | file, |
| struct iobuf * | io, | ||
| int | flags, | ||
| const struct sockaddr * | to, | ||
| socklen_t | tolen ) |
Sends data on a socket, for send(), sendto() and write().
| file | the socket |
| io | the data, in user memory |
| flags | MSG_* flags |
| to | the destination, for a datagram socket, or NULL |
| tolen | its size |
Definition at line 141 of file socket.c.
References FILE_SOCKET, file::flags, and socket_send().
Referenced by socket_send(), sys_send(), and vfs_file_write().
| int socket_setsockopt | ( | struct file * | file, |
| int | level, | ||
| int | name, | ||
| const void * | val, | ||
| socklen_t | len ) |
Sets a socket option, for setsockopt().
The protocol is asked first; a few common SOL_SOCKET options are accepted here without effect.
| file | the socket |
| level | SOL_SOCKET, or a protocol's level |
| name | the option |
| val | its value, in the kernel's memory |
| len | its size |
Definition at line 361 of file socket.c.
References FILE_SOCKET, file::flags, sock_ops::setsockopt, and socket_setsockopt().
Referenced by socket_setsockopt(), and sys_setsockopt().
| int socket_shutdown | ( | struct file * | file, |
| int | how ) |
Releases a socket when its open file is closed (its last descriptor went).
| file | the socket |
| how | passed on to the protocol |
Definition at line 267 of file socket.c.
References FILE_SOCKET, file::flags, and socket_shutdown().
Referenced by socket_shutdown(), and vfs_file_close().
| int socket_shutdown_dir | ( | struct file * | file, |
| int | how ) |
Shuts down reading, writing or both on a socket, for shutdown().
The socket stays open.
| file | the socket |
| how | SHUT_RD, SHUT_WR or SHUT_RDWR |
Definition at line 245 of file socket.c.
References FILE_SOCKET, file::flags, and socket_shutdown_dir().
Referenced by socket_shutdown_dir(), and sys_shutdown().
Finds the wait queue that a socket's readers (or writers) sleep on, for select() and poll() to register.
| file | the socket |
| write | 0 for readers, 1 for writers |
Definition at line 209 of file socket.c.
References NULL, and socket_wait_queue().
Referenced by socket_wait_queue(), and vfs_file_wait_queue().
|
static |
Sets an option's value to the int v.
Returns 0, or -EINVAL if *len has no room for an int.
Definition at line 302 of file socket.c.
References sockopt_int().
Referenced by socket_getsockopt(), and sockopt_int().