SourceForge.net Logo

AEM - The Linux Asynchronous Event Mechanism





Back to main page





























AEM IP

DESCRIPTION

The module aem-ip provides asynchronous capablities to certain system calls of the TCP/IP protocol: accept, read, close.

DEFINITIONS

#include <aem.h>
This file is located in the directory  {AEMSRC}/include/user in the AEM source package. It must be installed and included with your source code.

libaem
This is the AEM library. It is located in the directory  {AEMSRC}/lib in the AEM source package. It must be installed and linked with your source code.

INTERFACES


The following set of API is provided by libaem.

int aemIP_init (void);

Initialize the asynchronous TCP/IP functionality.

int aemIP_accept (int, struct sockaddr *, int *, void *);

The goal of this call is to register a handler that will be called directly and asynchronously once a connection occurs on the specified socket.  The parameters are the socket descriptor, the socket address, the socket address length and the accept handler address.

This call registers a handler for accept. This is a non-blocking call.
This is almost the same calling convention as the Unix accept() call except:
        1) the handler is provided in the last parameter,
        2) the addrlen parameter is NOT a value-result parameter. It must contain the length of the address and cannot be zero.
 
The call returns a positive value (an event Id) on success and a negative value (errno is set) on error. The new socket handler is passed to the accept handler  when there is a connection.
 
If the call returns success, the event has been created but is to be enabled explicitly by calling aemCORE_event_start()with the returned Id.
 
The handler must have this prototype:

          void accept_handler (int event_id, int old_sockfd, int new_sockfd);

The accept handler is called with the old and the new socket descriptor. The event Id is the one given during registration. If the event has been registered with the flags EVF_FORK care must be taken no to exit at the end of the accept handler.
 
int aemIP_read (int, void *);

This call permits to register a handler that will be directly and asynchronously called once data come in the socket specified by the first parameter.  The second parameter specifiies the handler to be called.

This call registers the handler for read. This is a non-blocking call.  It returns a positive value (an event Id) on success and a negative value (errno is set) on error.
 
If the call returns success, the event has been created but is to be enabled explicitly by calling aemCORE_event_start() with the returned Id.
 
The handler must have this prototype:

         void read_handler (int event_id, int sockfd, char *data_read, int data_len);

The read handler is directly called with the data and its length givent in parameter as well as the coresponding socket descriptor.
The event Id is the one given during registration. the pointer given by data is a user pointer. It can be read and written to but it MUST NOT be freed by the user.  See vmtable for more detail.

int aemIP_close (int, void *);


This call permits to regsiter a handler that will be called directly and asynchronously once a close is detected on the socket specified by the first parameter. The second parameter specifies the handler to be called.

This call registers the handler for close. This is a non-blocking call. It returns a positive value (an event Id) on success and a negative value (errno is set) on error.

If the call returns success, the event has been created but is to be enabled explicitly by calling aemCORE_event_start() with the returned Id.

The handler must have this prototype:

        void close_handler (int event_id, int socket_id);

The close handler is called with the closing socket descriptor as well as
the event Id given during registration.