run_async
Description:
[ Version ( deprecated = true ) ]
public void run_async ()
public void run_async ()
Warning: run_async is deprecated.
Starts this, if you are using the old API, causing it to listen for and process incoming connections.
Note:
When using listen, etc, the server will always listen for connections, and will process them whenever the thread-default MainContext is running.
The server runs in this's MainContext. It will not actually perform any processing unless the appropriate main loop is running. In the simple case where you did not set the server's SERVER_ASYNC_CONTEXT property, this means the server will run whenever the glib main loop is running.
Example: Simple server, async:
public class NoodleSoupServer : Soup.Server {
private int access_counter = 0;
public NoodleSoupServer () {
Object (port: 8088);
assert (this != null);
// Links:
// http://localhost:8088/*
this.add_handler (null, default_handler);
}
private static void default_handler (Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) {
unowned NoodleSoupServer self = server as NoodleSoupServer;
uint id = self.access_counter++;
print ("Default handler start (%u)\n", id);
// Simulate asynchronous input / time consuming operations:
// See GLib.IOSchedulerJob for time consuming operations
Timeout.add_seconds (0, () => {
string html_head = "<head><title>Index</title></head>";
string html_body = "<body><h1>Index:</h1></body>";
msg.set_response ("text/html", Soup.MemoryUse.COPY, "<html>%s%s</html>".printf (html_head, html_body).data);
// Resumes HTTP I/O on msg:
self.unpause_message (msg);
print ("Default handler end (%u)\n", id);
return false;
}, Priority.DEFAULT);
// Pauses HTTP I/O on msg:
self.pause_message (msg);
}
public static int main (string[] args) {
MainLoop loop = new MainLoop ();
NoodleSoupServer server = new NoodleSoupServer ();
server.run_async ();
loop.run ();
return 0;
}
}
valac --pkg libsoup-2.4 simple-server-async.vala
Parameters:
this |
a Server |