ThreadAnchor

An object which allows calling a function in a different thread. Create ThreadAnchor in the main thread (the thread in which the code will run in), and then call runWait or runAsync from a different thread.

The main thread must be running an unblocked ae.net.asockets event loop.

Constructors

this
this()
Undocumented in source.

Members

Functions

close
void close()
Undocumented in source. Be warned that the author may not have intended to support it.
runAsync
void runAsync(Dg dg)
Undocumented in source. Be warned that the author may not have intended to support it.
runWait
void runWait(Dg dg)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From TcpConnection

state
ConnectionState state [@property getter]

Get connection state.

outQueue
Data[][MAX_PRIORITY + 1] outQueue;

The send buffers.

partiallySent
bool[MAX_PRIORITY + 1] partiallySent;

Whether the first item from each queue has been partially sent (and thus can't be cancelled).

updateFlags
void updateFlags()
Undocumented in source. Be warned that the author may not have intended to support it.
onReadable
void onReadable()

Called when a socket is readable.

onWritable
void onWritable()

Called when a socket is writable.

onError
void onError(string reason)

Called when an error occurs on the socket.

tryNextAddress
void tryNextAddress()
Undocumented in source. Be warned that the author may not have intended to support it.
connect
void connect(string host, ushort port)

Start establishing a connection.

disconnect
void disconnect(string reason, DisconnectType type)

Close a connection. If there is queued data waiting to be sent, wait until it is sent before disconnecting. The disconnect handler will be called when all data has been flushed.

send
void send(Data[] data, int priority)
alias send = IConnection.send

Append data to the send buffer.

clearQueue
void clearQueue(int priority)
Undocumented in source. Be warned that the author may not have intended to support it.
writePending
bool writePending [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
queuePresent
bool queuePresent(int priority)
Undocumented in source. Be warned that the author may not have intended to support it.
handleConnect
ConnectHandler handleConnect [@property setter]

Callback for when a connection has been established.

handleBufferFlushed
void delegate() handleBufferFlushed;

Callback for when the send buffer has been flushed.

handleReadData
ReadDataHandler handleReadData [@property setter]

Callback for incoming data. Data will not be received unless this handler is set.

handleDisconnect
DisconnectHandler handleDisconnect [@property setter]

Callback for when a connection was closed.

Examples

void onConnect(TcpConnection socket)
{
	auto anchor = new ThreadAnchor;
	new Thread({
		string s = readln();
		anchor.runAsync({
			socket.send(s);
			socket.disconnect();
		});
	}).start();
}

Meta