ISocket

Abstract socket class

Constructors

this
this(socklen_t in_addrlen)

Constructor.

Destructor

~this
~this()

Destructor. Calls close() if indicated by close_in_destructor.

Members

Aliases

SocketFlags
alias SocketFlags = .SocketFlags

Flags supported by accept4().

Functions

accept
int accept(ISelectable listening_socket, sockaddr* remote_address, socklen_t addrlen, SocketFlags flags)

Accepts a connection from a listening socket and sets this.fd to the accepted socket file descriptor.

accept
int accept(ISelectable listening_socket, SocketFlags flags)

Accepts a connection from a listening socket and sets this.fd to the accepted socket file descriptor.

accept
int accept(ISelectable listening_socket, bool nonblocking)

Accepts a connection from a listening socket and sets this.fd to the accepted socket file descriptor.

bind
int bind(sockaddr* local_address)

Assigns a local address to this socket. This socket needs to have been created by socket().

clear
void clear()

Resets the file descriptor, address and port. Called from close(), should be called otherwise only in special situations.

close
int close()

Closes the socket and resets the file descriptor, address and port.

connect
int connect(sockaddr* remote_address)

Connects this socket the specified address and port.

error
int error()

Calls getsockopt(SOL_SOCKET, SO_ERROR) to obtain the current error code for this socket.

fileHandle
Handle fileHandle()

Required by ISelectable.

formatInfo
void formatInfo(char[] buf, bool io_error)

Formats information about the socket into the provided buffer.

getpeername
int getpeername(sockaddr* remote_address, socklen_t addrlen)

Obtains the remote socket address.

getsockname
int getsockname(sockaddr* local_address, socklen_t addrlen)

Obtains the local socket address.

getsockopt
ssize_t getsockopt(int level, int optname, void[] dst)

Obtains the value of a socket option, writing the value data to dst.

getsockoptVal
ssize_t getsockoptVal(int level, int optname, T val)

Calls getsockopt() to obtain the value of a socket option.

listen
int listen(int backlog)

listen() marks this socket as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept().

recv
ssize_t recv(void[] dst, int flags)

Receives dst.length bytes from the remote but at most as possible with one attempt.

send
ssize_t send(const(void)[] src, int flags)

Sends as many src bytes as possible to the remote.

setsockopt
int setsockopt(int level, int optname, const(void)[] src)

Sets the value of a socket option, using the value data in src. The actual value data type and length depends on the particular option.

setsockoptVal
int setsockoptVal(int level, int optname, T val)

Calls setsockopt() to sets the value of a socket option to val.

shutdown
int shutdown(int how)

The shutdown() call causes all or part of a full-duplex connection on the socket to be shut down.

socket
int socket(int domain, int type, int protocol)

Creates a socket endpoint for communication and sets this.fd to the corresponding file descriptor.

write
ssize_t write(const(void)[] src)

Calls send() to send as many src bytes as possible.

Static functions

error
int error(ISelectable socket)

Calls getsockopt(SOL_SOCKET, SO_ERROR) to obtain the current error code for the socket referred to by fd.

Variables

close_in_destructor
bool close_in_destructor;

If true, the destructor will call close(). Enabled by socket()/accept() on success, disabled by close() and socket()/accept() on failure. Should be modified otherwise only in special situations.

fd
int fd;

File descriptor. Set by socket()/accept() and reset by close() and clear(). Should be modified otherwise only in special situations.

in_addrlen
socklen_t in_addrlen;

Address struct (sin_addr/sin6_addr) length.

suppress_sigpipe
bool suppress_sigpipe;

If true, send() and therefore write() are requested not to send SIGPIPE on errors when this socket is stream oriented (e.g. TCP) and the other end breaks the connection.

Inherited Members

From IODevice

write
ssize_t write(const(void)[] src)

Attempts to write src.length bytes, see IOutputDevice.write() documentation.

Meta