13#include <aquila/errno.h>
16#include <aquila/fcntl.h>
64 if (!
file->socket->ops || !
file->socket->ops->accept)
67 int err =
file->socket->ops->accept(
file, conn, addr, len);
70 conn->
flags |= O_RDWR;
88 if (!
file->socket->ops || !
file->socket->ops->bind)
91 return file->socket->ops->bind(
file, addr, len);
107 if (!
file->socket->ops || !
file->socket->ops->connect)
110 return file->socket->ops->connect(
file, addr, len);
125 if (!
file->socket->ops || !
file->socket->ops->listen)
128 return file->socket->ops->listen(
file, backlog);
152 if (!
file->socket->ops || !
file->socket->ops->send)
155 return file->socket->ops->send(
file, io, flags, to, tolen);
174 if (!
file->socket->ops || !
file->socket->ops->recv)
177 return file->socket->ops->recv(
file, io, flags, from, fromlen);
194 if (!
file->socket->ops || !
file->socket->ops->can_read)
197 return file->socket->ops->can_read(
file, len);
211 if (!
file->socket->ops || !
file->socket->ops->wait_queue)
214 return file->socket->ops->wait_queue(
file, write);
230 if (!
file->socket->ops || !
file->socket->ops->can_write)
233 return file->socket->ops->can_write(
file, len);
250 if (how & ~SHUT_RDWR || !how)
253 if (!
file->socket->ops || !
file->socket->ops->shut)
256 return file->socket->ops->shut(
file, how);
272 if (!
file->socket->ops || !
file->socket->ops->shutdown)
276 return file->socket->ops->shutdown(
file, how);
294 if (!
file->socket->ops || !
file->socket->ops->getname)
297 return file->socket->ops->getname(
file, addr, len, peer);
304 if (*len <
sizeof(
int))
332 if (level == SOL_SOCKET && name == SO_TYPE)
338 if (err != -ENOPROTOOPT)
343 if (level == SOL_SOCKET && name == SO_ERROR)
371 if (err != -ENOPROTOOPT)
376 if (level == SOL_SOCKET) {
404 if (!
file->socket->ops || !
file->socket->ops->ioctl)
407 return file->socket->ops->ioctl(
file, request, argp);
static int sockopt_int(void *val, socklen_t *len, int v)
Sets an option's value to the int v.
int socket_listen(struct file *file, int backlog)
Makes a socket listen for connections, for listen().
int socket_inet_create(struct file *file, int domain, int type, int protocol)
Makes an AF_INET socket: a TCP, UDP or ping socket.
int socket_shutdown_dir(struct file *file, int how)
Shuts down reading, writing or both on a socket, for shutdown().
int socket_can_write(struct file *file, size_t len)
Says whether a socket has room to write, for select() and poll().
int socket_getsockopt(struct file *file, int level, int name, void *val, socklen_t *len)
Reads a socket option, for getsockopt().
int socket_connect(struct file *file, const struct sockaddr *addr, socklen_t len)
Connects a socket to a peer, for connect().
int socket_setsockopt(struct file *file, int level, int name, const void *val, socklen_t len)
Sets a socket option, for setsockopt().
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 regist...
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_unix_create(struct file *file, int domain, int type, int protocol)
Makes an AF_UNIX socket, 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_ioctl(struct file *file, int request, void *argp)
Handles an ioctl() on a socket, by passing it to the protocol.
int socket_shutdown(struct file *file, int how)
Releases a socket when its open file is closed (its last descriptor went).
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_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().
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().
int socket_bind(struct file *file, const struct sockaddr *addr, socklen_t len)
Gives a socket its local address, for bind().
An open file (POSIX's "open file description", fs/file.c).
A domain's socket operations.
int(*) setsockopt(struct file *socket, int level, int name, const void *val, socklen_t len)
int(*) getsockopt(struct file *socket, int level, int name, void *val, socklen_t *len)