[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A few technical questions



Shlomi Fish <shlomi@slink.co.il> wrote:
|2. Does anybody know of any way to perform asynchronous Berkely sockets
|calls on Linux? I mean that instead of blocking further execution calls
|such as accept(), or connect() will call a certain function that I specify
|once they are finished. Such stuff for the select() call will also be nice.

Read any good book about UNIX network programming, practically anything they say about sockets under UNIX applies to Linux.

More precisely - you can set a socket to "non-blocking" mode before
connect(2), then select(2) on it and wait for the conenct to finish
(or fail).  You can also select(2) on a passive socket and wait for
new connectiosn on it.

|Of course I can write my own library with a separate thread (or process?) for 
|every call that will exit by calling the handler I assigned, but I'm
|looking for a neater way.

It's not such "of course".  Such a solution would easely overload the
system.  Just read any book about basic UNIX network programming.

|3. I was still unable to write a simple multi-threaded program with the
|clone() system call. Not only does "#include <asm/unistd.h>" causes many
|errors, but after I fix them by defining a macro before the include, the
|call seems to do the same thing as a regular fork(). I also noticed that
|its two parameters are appearently in the opposite order than what is
|documented in the manual page, but reversing them won't help either. I've
|tried to run it even without X but to no avail.

Leave clone(2) alone.  Use the LinuxThreads-based POSIX threads.  That
way your code will be more portable too.

--Amos

--Amos Shapira                    | "Of course Australia was marked for
133 Shlomo Ben-Yosef st.          |  glory, for its people had been chosen
Jerusalem 93 805                  |  by the finest judges in England."
ISRAEL        amos@gezernet.co.il |                     -- Anonymous


References: