Categories

Port of Call

Today I managed to get an implementation of the green client/server model running under Linux.

I started from some proof of concept code that was written for Windows and the vast majority of the porting work was in translating Windows specific code to run on Linux.

There were three major “types” of code that had to be translated:

1. Threads
2. Semaphores
3. User Interface

The thread code was relatively simple to port. Because there wasn’t anything too fancy going on in the Windows code, I just had to modify some CreateThread() calls to use pthread_create().

The semaphore related code was likewise easy to port e.g. replacing WaitForSingleObject() with sem_wait() and substituting sem_post() for ReleaseSemaphore().

The user interface code changes were by far the most time consuming. In the Windows code, kbhit() and getch() were used to “pause” the client long enough to simulate a network disconnect. Unfortunately, kbhit() and getch() are not part of the C library on Linux and due to the manner in which Linux (and other Unix-like operating systems) handles terminal input/output the ensuing work around code has a strong odor of hack on it. On the other hand, these calls weren’t really necessary as a simple ctrl-c of the client will do far more than simulate a network disconnect: it will actually perform one.

Once the above were completed, I got my first taste of a working green application. Instead of the normal situation of the server viewing a client disconnect as an indication that server side processing should stop, the server continues processing and buffers any output that would normally be sent to the client. Upon client reconnect, the server dumps all the buffered output back to the client. It’s a beautiful thing.

I’m now firmly convinced that a framework and/or kernel modifications could be made to ease the conversion of standard client/server model applications to the green model, or even make the change transparent.

But first I have to get everything working in telnetd…

Comments are closed.