The OpenD Programming Language

FiberSocket

Subclass of Phobos' socket that basically works the same way, except it yields back to the FiberManager when it would have blocked.

You should not modify the blocking flag on these and generally not construct them, connect them, or listen on them yourself (let FiberManager do the setup for you), but otherwise they work the same as the original Phobos std.socket.Socket and implement the very same interface. You can call the exact same functions with original Sockets or FiberSockets.

Constructors

this
this(FiberManager fm, AddressFamily af, SocketType st, Fiber fiber)

You should probably call the helper functions in FiberManager instead.

Members

Aliases

receive
alias receive = typeof(super).receive
receiveFrom
alias receiveFrom = typeof(super).receiveFrom

The Phobos overloads are still available too, they forward to the overrides in this class and thus work the same way.

send
alias send = typeof(super).send
sendTo
alias sendTo = typeof(super).sendTo

The Phobos overloads are still available too, they forward to the overrides in this class and thus work the same way.

Functions

receive
ptrdiff_t receive(void[] buf, SocketFlags flags)
receiveFrom
ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, Address from)
ptrdiff_t receiveFrom(void[] buf, SocketFlags flags)

Yielding override of the Phobos interface

send
ptrdiff_t send(const(void)[] buf, SocketFlags flags)
sendTo
ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to)
ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags)

Yielding override of the Phobos interface

Inherited Members

From Socket

handle
socket_t handle [@property getter]

Get underlying socket handle.

release
socket_t release [@property getter]

Releases the underlying socket handle from the Socket object. Once it is released, you cannot use the Socket object's methods anymore. This also means the Socket destructor will no longer close the socket - it becomes your responsibility.

blocking
bool blocking [@property getter]
bool blocking [@property setter]

Get/set socket's blocking flag.

addressFamily
AddressFamily addressFamily [@property getter]

Get the socket's address family.

isAlive
bool isAlive [@property getter]

Property that indicates if this is a valid, alive socket.

bind
void bind(Address addr)

Associate a local address with this socket.

connect
void connect(Address to)

Establish a connection. If the socket is blocking, connect waits for the connection to be made. If the socket is nonblocking, connect returns immediately and the connection attempt is still in progress.

listen
void listen(int backlog)

Listen for an incoming connection. bind must be called before you can listen. The backlog is a request of how many pending incoming connections are queued until accepted.

accepting
Socket accepting()

Called by accept when a new Socket must be created for a new connection. To use a derived class, override this method and return an instance of your class. The returned Socket's handle must not be set; Socket has a protected constructor this() to use in this situation.

accept
Socket accept()

Accept an incoming connection. If the socket is blocking, accept waits for a connection request. Throws SocketAcceptException if unable to accept. See accepting for use with derived classes.

shutdown
void shutdown(SocketShutdown how)

Disables sends and/or receives.

close
void close()

Immediately drop any connections and release socket resources. The Socket object is no longer usable after close. Calling shutdown before close is recommended for connection-oriented sockets.

hostName
string hostName [@property getter]
remoteAddress
Address remoteAddress [@property getter]

Remote endpoint Address.

localAddress
Address localAddress [@property getter]

Local endpoint Address.

ERROR
enum int ERROR;

Send or receive error code. See wouldHaveBlocked, lastSocketError and Socket.getErrorText for obtaining more information about the error.

send
ptrdiff_t send(const(void)[] buf, SocketFlags flags)
ptrdiff_t send(const(void)[] buf)

Send data on the connection. If the socket is blocking and there is no buffer space left, send waits.

sendTo
ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to)
ptrdiff_t sendTo(const(void)[] buf, Address to)
ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags)
ptrdiff_t sendTo(const(void)[] buf)

Send data to a specific destination Address. If the destination address is not specified, a connection must have been made and that address is used. If the socket is blocking and there is no buffer space left, sendTo waits.

receive
ptrdiff_t receive(void[] buf, SocketFlags flags)
ptrdiff_t receive(void[] buf)

Receive data on the connection. If the socket is blocking, receive waits until there is data to be received.

receiveFrom
ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, Address from)
ptrdiff_t receiveFrom(void[] buf, Address from)
ptrdiff_t receiveFrom(void[] buf, SocketFlags flags)
ptrdiff_t receiveFrom(void[] buf)

Receive data and get the remote endpoint Address. If the socket is blocking, receiveFrom waits until there is data to be received.

getOption
int getOption(SocketOptionLevel level, SocketOption option, void[] result)

Get a socket option.

getOption
int getOption(SocketOptionLevel level, SocketOption option, int32_t result)

Common case of getting integer and boolean options.

getOption
int getOption(SocketOptionLevel level, SocketOption option, Linger result)

Get the linger option.

getOption
void getOption(SocketOptionLevel level, SocketOption option, Duration result)

Get a timeout (duration) option.

setOption
void setOption(SocketOptionLevel level, SocketOption option, void[] value)

Set a socket option.

setOption
void setOption(SocketOptionLevel level, SocketOption option, int32_t value)

Common case for setting integer and boolean options.

setOption
void setOption(SocketOptionLevel level, SocketOption option, Linger value)

Set the linger option.

setOption
void setOption(SocketOptionLevel level, SocketOption option, Duration value)

Sets a timeout (duration) option, i.e. SocketOption.SNDTIMEO or RCVTIMEO. Zero indicates no timeout.

getErrorText
string getErrorText()

Get a text description of this socket's error status, and clear the socket's error status.

setKeepAlive
void setKeepAlive(int time, int interval)

Enables TCP keep-alive with the specified parameters.

select
int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, Duration timeout)
int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError)
int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, TimeVal* timeout)

Wait for a socket to change status. A wait timeout of core.time.Duration or TimeVal, may be specified; if a timeout is not specified or the TimeVal is null, the maximum timeout is used. The TimeVal timeout has an unspecified value when select returns.

createAddress
Address createAddress()

Can be overridden to support other addresses.

Meta