1<!-- Creator : groff version 1.22.3 --> 2<!-- CreationDate: Mon Aug 28 02:48:47 2017 --> 3<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 4"http://www.w3.org/TR/html4/loose.dtd"> 5<html> 6<head> 7<meta name="generator" content="groff -Thtml, see www.gnu.org"> 8<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> 9<meta name="Content-Style" content="text/css"> 10<style type="text/css"> 11 p { margin-top: 0; margin-bottom: 0; vertical-align: top } 12 pre { margin-top: 0; margin-bottom: 0; vertical-align: top } 13 table { margin-top: 0; margin-bottom: 0; vertical-align: top } 14 h1 { text-align: center } 15</style> 16<title>mtcp_define_event</title> 17<link rel="stylesheet" href="./common.css"> 18</head> 19<body> 20<div class="main"> 21<h1 align="center">mtcp_define_event</h1> 22<!-- 23<a href="#NAME">NAME</a><br> 24<a href="#SYNOPSIS">SYNOPSIS</a><br> 25<a href="#DESCRIPTION">DESCRIPTION</a><br> 26<a href="#RETURN VALUE">RETURN VALUE</a><br> 27<a href="#ERRORS">ERRORS</a><br> 28<a href="#AUTHORS">AUTHORS</a><br> 29<a href="#SEE ALSO">SEE ALSO</a><br> 30<a href="#COLOPHON">COLOPHON</a><br> 31 32<hr> 33--> 34 35<h2>NAME 36<a name="NAME"></a> 37</h2> 38 39 40 41<p style="margin-left:11%; margin-top: 1em">mtcp_define_event 42− define a user-defined event function</p> 43 44<h2>SYNOPSIS 45<a name="SYNOPSIS"></a> 46</h2> 47 48 49<p style="margin-left:11%; margin-top: 1em"><b>#include 50<mos_api.h></b></p> 51 52<p style="margin-left:11%; margin-top: 1em"><b>int 53mtcp_define_event(event_t</b> <i>event</i><b>, filter_t</b> 54<i>filter</i><b>, struct filter_arg *</b> <i>arg</i> 55<b>);</b></p> 56 57<h2>DESCRIPTION 58<a name="DESCRIPTION"></a> 59</h2> 60 61 62 63<p style="margin-left:11%; margin-top: 1em"><b>mtcp_define_event</b>() 64creates a new user-defined event (UDE) with a base event 65<i>event</i> and a filter function <i>filter</i> with a 66filter argument <i>arg</i></p> 67 68<p style="margin-left:11%; margin-top: 1em">More 69specifically, a UDE is defined as a based event and a 70boolean filter function that determines the event condition. 71When the base event for a UDE is raised, mOS triggers the 72UDE only when the filter function is evaluated to be 73true.</p> 74 75<p style="margin-left:11%; margin-top: 1em"><i>event</i> 76argument is a typedef’ed uint64_t integer. It can be 77either a built-in event or a user-defined event. mOS 78provides the following built-in events that a user can 79employ:</p> 80 81 82<p align="center" style="margin-top: 1em"> 83 <table align="center" border="1" class="docutils"> 84 <colgroup> 85 <col width="40%" /> 86 <col width="60%" /> 87 </colgroup> 88 <tbody valign="top"> 89 <tr class="row-odd"><td>Built-in event</td> 90 <td>Description</td> 91 </tr> 92 <tr class="row-even"><td><code class="docutils literal"><span class="pre">MOS_ON_PKT_IN</span></code></td> 93 <td>In-flow TCP packet arrival</td> 94 </tr> 95 <tr class="row-odd"><td><code class="docutils literal"><span class="pre">MOS_ON_CONN_START</span></code></td> 96 <td>New connection initiation</td> 97 </tr> 98 <tr class="row-even"><td><code class="docutils literal"><span class="pre">MOS_ON_REXMIT</span></code></td> 99 <td>TCP retransmission</td> 100 </tr> 101 <tr class="row-odd"><td><code class="docutils literal"><span class="pre">MOS_ON_TCP_STATE_CHANGE</span></code></td> 102 <td>TCP state change</td> 103 </tr> 104 <tr class="row-even"><td><code class="docutils literal"><span class="pre">MOS_ON_CONN_END</span></code></td> 105 <td>Connection termination</td> 106 </tr> 107 <tr class="row-odd"><td><code class="docutils literal"><span class="pre">MOS_ON_CONN_NEW_DATA</span></code></td> 108 <td>New flow payload</td> 109 </tr> 110 <tr class="row-even"><td><code class="docutils literal"><span class="pre">MOS_ON_ORPHAN</span></code></td> 111 <td>non-TCP packet</td> 112 </tr> 113 <tr class="row-odd"><td><code class="docutils literal"><span class="pre">MOS_ON_ERROR</span></code></td> 114 <td>Error report (e.g., receive buffer full)</td> 115 </tr> 116 </tbody> 117 </table> 118</p> 119 120<p style="margin-left:11%; margin-top: 1em">A typical usage 121of <b>mtcp_define_event()</b> is illustrated below:</p> 122 123 124<p style="margin-left:11%; margin-top: 1em">/*************************************************/ 125<br> 126// creates a passive monitoring socket with its scope <br> 127s = mtcp_socket(m, AF_INET, MOS_SOCK_MONITOR_STREAM, 0); 128<br> 129ft.stream_syn_filter = "dst net 216.58 and dst port 13080"; <br> 131mtcp_bind_monitor_filter(m, s, &ft);</p> 132 133<p style="margin-left:11%; margin-top: 1em">// defines a 134user-defined event that detects an HTTP request <br> 135hev = mtcp_define_event(MOS_ON_CONN_NEW_DATA, IsHTTPRequest, 136NULL); <br> 137/*************************************************/</p> 138 139<h2>RETURN VALUE 140<a name="RETURN VALUE"></a> 141</h2> 142 143 144<p style="margin-left:11%; margin-top: 1em">Returns 0 on 145success; -1 on failure.</p> 146 147<h2>ERRORS 148<a name="ERRORS"></a> 149</h2> 150 151 152<table width="100%" border="0" rules="none" frame="void" 153 cellspacing="0" cellpadding="0"> 154<tr valign="top" align="left"> 155<td width="11%"></td> 156<td width="9%"> 157 158 159<p style="margin-top: 1em"><b>EINVAL</b></p></td> 160<td width="14%"></td> 161<td width="63%"> 162 163 164<p style="margin-top: 1em">The socket descriptor, 165<i>sockid</i> is invalid.</p></td> 166<td width="3%"> 167</td></tr> 168</table> 169 170<h2>AUTHORS 171<a name="AUTHORS"></a> 172</h2> 173 174<!-----------------------------------------------------------> 175<h2>EXAMPLES 176<a name="EXAMPLES"></a> 177</h2> 178 179<p style="margin-left:11%; margin-top: 1em"> 180 <a href="http://mos.kaist.edu/guide/programmer/05_api_example.html#registering-for-user-defined-events-udes"> 181 http://mos.kaist.edu/guide/programmer/05_api_example.html#registering-for-user-defined-events-udes 182 </a> 183</p> 184<!-----------------------------------------------------------> 185 186<p style="margin-left:11%; margin-top: 1em">mOS development 187team <[email protected]></p> 188 189<h2>SEE ALSO 190<a name="SEE ALSO"></a> 191</h2> 192 193 194 195<p style="margin-left:11%; margin-top: 1em"><b>mtcp_socket</b>(), 196<b>mtcp_bind_monitor_filter</b>(), 197<b>mtcp_register_callback</b>()</p> 198 199<h2>COLOPHON 200<a name="COLOPHON"></a> 201</h2> 202 203 204<p style="margin-left:11%; margin-top: 1em">This page is 205part of mOS release 0.3 <i>docs</i> section. A description 206of the project, and information about reporting bugs, can be 207found at http://mos.kaist.edu/.</p> 208<hr> 209<div class="footer"> 210 <img src="back-arrow.jpg" width="2%" height="2%"><a href="http://mos.kaist.edu/index_man.html">Back to Index</a> 211</div> 212</div> 213</body> 214</html> 215