
The K Desktop Environment (KDE) I/O slaves (ioslaves) are a series of small programs that have intimate knowledge on working with a very specific protocol. For instance, the HTTP ioslave (kio_http) knows all about sending and receiving data to and from a web server. It knows all about SSL, encoding, and what all of the different header fields mean. It knows this so that KDE developers won't have to -- if they want a web page, they merely have to use kio_http for it and it will take care of everything for them.
The ioslaves are based on the KIO library (libkio). This library implements a method of asynchronous communication between applications as well as provides a "protocol registry" of sorts. This has many advantages. Two of the major ones are:
The client does not need to know anything about the ioslave that it is calling. It merely specifies the protocol and libkio will automatically determine the proper ioslave to use.
All communication is done asynchronously. All libkio calls will return immediately. Whenever events occur, libkio will send signals altering the client to that fact. This means that the client does not have to engage in any "busy waiting."
Here is a fully working snippet of code to download a web page:
KIO::TransferJob *job = KIO::get("http://www.kde.org/news_dyn.html");
connect(job, SIGNAL(result(KIO::Job *)),
this, SLOT(slotResult(KIO::Job *)));
connect(job, SIGNAL(data(KIO::Job *, const QByteArray&)),
this, SLOT(slotData(KIO::Job *, const QByteArray&))); |
That's it! The ioslave will download the KDE news page asynchronously. With each chunk of the page it downloads, it will pass it along to your application's slotData() function. When it finishes (for whatever reason), slotResult() will be called.
Copyright (c) 2000 Kurt Granroth, All rights reserved. This is free documentware; you can redistribute it and/or modify it in any way you like as long as you leave this copyright intact.