mtcp_define_event

NAME

mtcp_define_event − define a user-defined event function

SYNOPSIS

#include <mos_api.h>

int mtcp_define_event(event_t event, filter_t filter, struct filter_arg * arg );

DESCRIPTION

mtcp_define_event() creates a new user-defined event (UDE) with a base event event and a filter function filter with a filter argument arg

More specifically, a UDE is defined as a based event and a boolean filter function that determines the event condition. When the base event for a UDE is raised, mOS triggers the UDE only when the filter function is evaluated to be true.

event argument is a typedef’ed uint64_t integer. It can be either a built-in event or a user-defined event. mOS provides the following built-in events that a user can employ:

Built-in event Description
MOS_ON_PKT_IN In-flow TCP packet arrival
MOS_ON_CONN_START New connection initiation
MOS_ON_REXMIT TCP retransmission
MOS_ON_TCP_STATE_CHANGE TCP state change
MOS_ON_CONN_END Connection termination
MOS_ON_CONN_NEW_DATA New flow payload
MOS_ON_ORPHAN non-TCP packet
MOS_ON_ERROR Error report (e.g., receive buffer full)

A typical usage of mtcp_define_event() is illustrated below:

/*************************************************/
// creates a passive monitoring socket with its scope
s = mtcp_socket(m, AF_INET, MOS_SOCK_MONITOR_STREAM, 0);
ft.stream_syn_filter = "dst net 216.58 and dst port 80";
mtcp_bind_monitor_filter(m, s, &ft);

// defines a user-defined event that detects an HTTP request
hev = mtcp_define_event(MOS_ON_CONN_NEW_DATA, IsHTTPRequest, NULL);
/*************************************************/

RETURN VALUE

Returns 0 on success; -1 on failure.

ERRORS

EINVAL

The socket descriptor, sockid is invalid.

AUTHORS

EXAMPLES

http://mos.kaist.edu/guide/programmer/05_api_example.html#registering-for-user-defined-events-udes

mOS development team <mtcp-user@list.ndsl.kaist.edu>

SEE ALSO

mtcp_socket(), mtcp_bind_monitor_filter(), mtcp_register_callback()

COLOPHON

This page is part of mOS release 0.3 docs section. A description of the project, and information about reporting bugs, can be found at http://mos.kaist.edu/.