\doxysection{nonblocking\+\_\+server\+\_\+example.\+c}
\hypertarget{nonblocking__server__example_8c_source}{}\label{nonblocking__server__example_8c_source}\index{nonblocking\_server\_example.c@{nonblocking\_server\_example.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00001}00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00002}00002\ \textcolor{comment}{\ *\ \ nonblocking\_server\_example.c}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00003}00003\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00004}00004\ \textcolor{comment}{\ *\ \ This\ code\ demonstrates\ two\ methods\ of\ monitoring\ both\ an\ lo\_server}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00005}00005\ \textcolor{comment}{\ *\ \ and\ other\ I/O\ from\ a\ single\ thread.}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00006}00006\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00007}00007\ \textcolor{comment}{\ *\ \ Copyright\ (C)\ 2014\ Steve\ Harris\ et\ al.\ (see\ AUTHORS)}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00008}00008\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00009}00009\ \textcolor{comment}{\ *\ \ This\ program\ is\ free\ software;\ you\ can\ redistribute\ it\ and/or\ modify}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00010}00010\ \textcolor{comment}{\ *\ \ it\ under\ the\ terms\ of\ the\ GNU\ Lesser\ General\ Public\ License\ as}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00011}00011\ \textcolor{comment}{\ *\ \ published\ by\ the\ Free\ Software\ Foundation;\ either\ version\ 2.1\ of\ the}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00012}00012\ \textcolor{comment}{\ *\ \ License,\ or\ (at\ your\ option)\ any\ later\ version.}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00013}00013\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00014}00014\ \textcolor{comment}{\ *\ \ This\ program\ is\ distributed\ in\ the\ hope\ that\ it\ will\ be\ useful,}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00015}00015\ \textcolor{comment}{\ *\ \ but\ WITHOUT\ ANY\ WARRANTY;\ without\ even\ the\ implied\ warranty\ of}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00016}00016\ \textcolor{comment}{\ *\ \ MERCHANTABILITY\ or\ FITNESS\ FOR\ A\ PARTICULAR\ PURPOSE.\ \ See\ the}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00017}00017\ \textcolor{comment}{\ *\ \ GNU\ Lesser\ General\ Public\ License\ for\ more\ details.}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00018}00018\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00019}00019\ \textcolor{comment}{\ *\ \ \$Id\$}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00020}00020\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00021}00021\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00022}00022\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00023}00023\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00024}00024\ \textcolor{preprocessor}{\#include\ <sys/types.h>}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00025}00025\ \textcolor{preprocessor}{\#ifndef\ WIN32}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00026}00026\ \textcolor{preprocessor}{\#include\ <sys/time.h>}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00027}00027\ \textcolor{preprocessor}{\#include\ <unistd.h>}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00028}00028\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00029}00029\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00030}00030\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{lo_8h}{lo/lo.h}}"{}}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00031}00031\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00032}00032\ \textcolor{keywordtype}{int}\ done\ =\ 0;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00033}00033\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00034}00034\ \textcolor{keywordtype}{void}\ error(\textcolor{keywordtype}{int}\ num,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *m,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00035}00035\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00036}00036\ \textcolor{keywordtype}{int}\ generic\_handler(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *types,\ \mbox{\hyperlink{unionlo__arg}{lo\_arg}}\ **\ argv,}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00037}00037\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ argc,\ \mbox{\hyperlink{lo__types_8h_a50be181dde1a8d313dbc7e48d4032210}{lo\_message}}\ data,\ \textcolor{keywordtype}{void}\ *user\_data);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00038}00038\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00039}00039\ \textcolor{keywordtype}{int}\ foo\_handler(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *types,\ \mbox{\hyperlink{unionlo__arg}{lo\_arg}}\ **\ argv,}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00040}00040\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ argc,\ \mbox{\hyperlink{lo__types_8h_a50be181dde1a8d313dbc7e48d4032210}{lo\_message}}\ data,\ \textcolor{keywordtype}{void}\ *user\_data);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00041}00041\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00042}00042\ \textcolor{keywordtype}{int}\ quit\_handler(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *types,\ \mbox{\hyperlink{unionlo__arg}{lo\_arg}}\ **\ argv,}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00043}00043\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ argc,\ \mbox{\hyperlink{lo__types_8h_a50be181dde1a8d313dbc7e48d4032210}{lo\_message}}\ data,\ \textcolor{keywordtype}{void}\ *user\_data);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00044}00044\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00045}00045\ \textcolor{keywordtype}{void}\ read\_stdin(\textcolor{keywordtype}{void});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00046}00046\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00047}00047\ \textcolor{keywordtype}{int}\ main()}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00048}00048\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00049}00049\ \ \ \ \ \textcolor{keywordtype}{int}\ lo\_fd;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00050}00050\ \ \ \ \ fd\_set\ rfds;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00051}00051\ \textcolor{preprocessor}{\#ifndef\ WIN32}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00052}00052\ \ \ \ \ \textcolor{keyword}{struct\ }timeval\ tv;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00053}00053\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00054}00054\ \ \ \ \ \textcolor{keywordtype}{int}\ retval;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00055}00055\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00056}00056\ \ \ \ \ \textcolor{comment}{/*\ start\ a\ new\ server\ on\ port\ 7770\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00057}00057\ \ \ \ \ \mbox{\hyperlink{lo__types_8h_a009a4f26c17bfcc1c31efc45499d09b8}{lo\_server}}\ s\ =\ \mbox{\hyperlink{group__liblolowlevel_ga78cfb23346e44465695293d4393447ae}{lo\_server\_new}}(\textcolor{stringliteral}{"{}7770"{}},\ error);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00058}00058\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00059}00059\ \ \ \ \ \textcolor{comment}{/*\ add\ method\ that\ will\ match\ any\ path\ and\ args\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00060}00060\ \ \ \ \ \mbox{\hyperlink{group__liblolowlevel_ga56c5f1d587c215c27e92e6436e12b1a3}{lo\_server\_add\_method}}(s,\ NULL,\ NULL,\ generic\_handler,\ NULL);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00061}00061\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00062}00062\ \ \ \ \ \textcolor{comment}{/*\ add\ method\ that\ will\ match\ the\ path\ /foo/bar,\ with\ two\ numbers,\ coerced}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00063}00063\ \textcolor{comment}{\ \ \ \ \ *\ to\ float\ and\ int\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00064}00064\ \ \ \ \ \mbox{\hyperlink{group__liblolowlevel_ga56c5f1d587c215c27e92e6436e12b1a3}{lo\_server\_add\_method}}(s,\ \textcolor{stringliteral}{"{}/foo/bar"{}},\ \textcolor{stringliteral}{"{}fi"{}},\ foo\_handler,\ NULL);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00065}00065\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00066}00066\ \ \ \ \ \textcolor{comment}{/*\ add\ method\ that\ will\ match\ the\ path\ /quit\ with\ no\ args\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00067}00067\ \ \ \ \ \mbox{\hyperlink{group__liblolowlevel_ga56c5f1d587c215c27e92e6436e12b1a3}{lo\_server\_add\_method}}(s,\ \textcolor{stringliteral}{"{}/quit"{}},\ \textcolor{stringliteral}{"{}"{}},\ quit\_handler,\ NULL);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00068}00068\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00069}00069\ \ \ \ \ \textcolor{comment}{/*\ get\ the\ file\ descriptor\ of\ the\ server\ socket,\ if\ supported\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00070}00070\ \ \ \ \ lo\_fd\ =\ \mbox{\hyperlink{group__liblolowlevel_gae11ca5a5b4ec2943d5a04642ba5052ae}{lo\_server\_get\_socket\_fd}}(s);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00071}00071\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00072}00072\ \ \ \ \ \textcolor{keywordflow}{if}\ (lo\_fd\ >\ 0)\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00073}00073\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00074}00074\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ select()\ on\ lo\_server\ fd\ is\ supported,\ so\ we'll\ use\ select()}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00075}00075\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ to\ watch\ both\ stdin\ and\ the\ lo\_server\ fd.\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00076}00076\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00077}00077\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00078}00078\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00079}00079\ \ \ \ \ \ \ \ \ \ \ \ \ FD\_ZERO(\&rfds);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00080}00080\ \textcolor{preprocessor}{\#ifndef\ WIN32}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00081}00081\ \ \ \ \ \ \ \ \ \ \ \ \ FD\_SET(0,\ \&rfds);\ \ \ \textcolor{comment}{/*\ stdin\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00082}00082\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00083}00083\ \ \ \ \ \ \ \ \ \ \ \ \ FD\_SET(lo\_fd,\ \&rfds);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00084}00084\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00085}00085\ \ \ \ \ \ \ \ \ \ \ \ \ retval\ =\ select(lo\_fd\ +\ 1,\ \&rfds,\ NULL,\ NULL,\ NULL);\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ no\ timeout\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00086}00086\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00087}00087\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (retval\ ==\ -\/1)\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00088}00088\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00089}00089\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}select()\ error\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00090}00090\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00091}00091\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00092}00092\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (retval\ >\ 0)\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00093}00093\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00094}00094\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (FD\_ISSET(0,\ \&rfds))\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00095}00095\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00096}00096\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ read\_stdin();}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00097}00097\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00098}00098\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00099}00099\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (FD\_ISSET(lo\_fd,\ \&rfds))\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00100}00100\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00101}00101\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__liblolowlevel_ga784a257252d05cc0e7210f4691f0661b}{lo\_server\_recv\_noblock}}(s,\ 0);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00102}00102\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00103}00103\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00104}00104\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00105}00105\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00106}00106\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (!done);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00107}00107\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00108}00108\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00109}00109\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00110}00110\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ lo\_server\ protocol\ does\ not\ support\ select(),\ so\ we'll\ watch}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00111}00111\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ stdin\ while\ polling\ the\ lo\_server.\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00112}00112\ \textcolor{preprocessor}{\#ifdef\ WIN32}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00113}00113\ \ \ \ \ \ \ \ \ printf}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00114}00114\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}non-\/blocking\ input\ from\ stdin\ not\ supported\ under\ Windows\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00115}00115\ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00116}00116\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00117}00117\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{do}\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00118}00118\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00119}00119\ \ \ \ \ \ \ \ \ \ \ \ \ FD\_ZERO(\&rfds);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00120}00120\ \ \ \ \ \ \ \ \ \ \ \ \ FD\_SET(0,\ \&rfds);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00121}00121\ \ \ \ \ \ \ \ \ \ \ \ \ tv.tv\_sec\ =\ 0;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00122}00122\ \ \ \ \ \ \ \ \ \ \ \ \ tv.tv\_usec\ =\ 10000;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00123}00123\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00124}00124\ \ \ \ \ \ \ \ \ \ \ \ \ retval\ =\ select(1,\ \&rfds,\ NULL,\ NULL,\ \&tv);\ \textcolor{comment}{/*\ timeout\ every\ 10ms\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00125}00125\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00126}00126\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (retval\ ==\ -\/1)\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00127}00127\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00128}00128\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}select()\ error\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00129}00129\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00130}00130\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00131}00131\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (retval\ >\ 0\ \&\&\ FD\_ISSET(0,\ \&rfds))\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00132}00132\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00133}00133\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ read\_stdin();}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00134}00134\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00135}00135\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00136}00136\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00137}00137\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__liblolowlevel_ga784a257252d05cc0e7210f4691f0661b}{lo\_server\_recv\_noblock}}(s,\ 0);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00138}00138\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00139}00139\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{while}\ (!done);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00140}00140\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00141}00141\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00142}00142\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00143}00143\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00144}00144\ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00145}00145\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00146}00146\ \textcolor{keywordtype}{void}\ error(\textcolor{keywordtype}{int}\ num,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *msg,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path)}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00147}00147\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00148}00148\ \ \ \ \ printf(\textcolor{stringliteral}{"{}liblo\ server\ error\ \%d\ in\ path\ \%s:\ \%s\(\backslash\)n"{}},\ num,\ path,\ msg);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00149}00149\ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00150}00150\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00151}00151\ \textcolor{comment}{/*\ catch\ any\ incoming\ messages\ and\ display\ them.\ returning\ 1\ means\ that\ the}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00152}00152\ \textcolor{comment}{\ *\ message\ has\ not\ been\ fully\ handled\ and\ the\ server\ should\ try\ other\ methods\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00153}00153\ \textcolor{keywordtype}{int}\ generic\_handler(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *types,\ \mbox{\hyperlink{unionlo__arg}{lo\_arg}}\ **\ argv,}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00154}00154\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ argc,\ \mbox{\hyperlink{lo__types_8h_a50be181dde1a8d313dbc7e48d4032210}{lo\_message}}\ data,\ \textcolor{keywordtype}{void}\ *user\_data)}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00155}00155\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00156}00156\ \ \ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00157}00157\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00158}00158\ \ \ \ \ printf(\textcolor{stringliteral}{"{}path:\ <\%s>\(\backslash\)n"{}},\ path);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00159}00159\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ argc;\ i++)\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00160}00160\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}arg\ \%d\ '\%c'\ "{}},\ i,\ types[i]);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00161}00161\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__pp_ga1699678a3a2d4221bb55fa2e05326ef0}{lo\_arg\_pp}}((\mbox{\hyperlink{group__liblo_ga11838c576b0197c255ce805fd7434736}{lo\_type}})types[i],\ argv[i]);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00162}00162\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00163}00163\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00164}00164\ \ \ \ \ printf(\textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00165}00165\ \ \ \ \ fflush(stdout);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00166}00166\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00167}00167\ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00168}00168\ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00169}00169\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00170}00170\ \textcolor{keywordtype}{int}\ foo\_handler(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *types,\ \mbox{\hyperlink{unionlo__arg}{lo\_arg}}\ **\ argv,}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00171}00171\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ argc,\ \mbox{\hyperlink{lo__types_8h_a50be181dde1a8d313dbc7e48d4032210}{lo\_message}}\ data,\ \textcolor{keywordtype}{void}\ *user\_data)}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00172}00172\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00173}00173\ \ \ \ \ \textcolor{comment}{/*\ example\ showing\ pulling\ the\ argument\ values\ out\ of\ the\ argv\ array\ */}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00174}00174\ \ \ \ \ printf(\textcolor{stringliteral}{"{}\%s\ <-\/\ f:\%f,\ i:\%d\(\backslash\)n\(\backslash\)n"{}},\ path,\ argv[0]-\/>f,\ argv[1]-\/>i);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00175}00175\ \ \ \ \ fflush(stdout);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00176}00176\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00177}00177\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00178}00178\ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00179}00179\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00180}00180\ \textcolor{keywordtype}{int}\ quit\_handler(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *path,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *types,\ \mbox{\hyperlink{unionlo__arg}{lo\_arg}}\ **\ argv,}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00181}00181\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ argc,\ \mbox{\hyperlink{lo__types_8h_a50be181dde1a8d313dbc7e48d4032210}{lo\_message}}\ data,\ \textcolor{keywordtype}{void}\ *user\_data)}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00182}00182\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00183}00183\ \ \ \ \ done\ =\ 1;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00184}00184\ \ \ \ \ printf(\textcolor{stringliteral}{"{}quiting\(\backslash\)n\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00185}00185\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00186}00186\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00187}00187\ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00188}00188\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00189}00189\ \textcolor{keywordtype}{void}\ read\_stdin(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00190}00190\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00191}00191\ \textcolor{preprocessor}{\#ifdef\ WIN32}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00192}00192\ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00193}00193\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00194}00194\ \ \ \ \ \textcolor{keywordtype}{char}\ buf[256];}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00195}00195\ \ \ \ \ \textcolor{keywordtype}{int}\ len\ =\ read(0,\ buf,\ 256);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00196}00196\ \ \ \ \ \textcolor{keywordflow}{if}\ (len\ >\ 0)\ \{}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00197}00197\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}stdin:\ "{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00198}00198\ \ \ \ \ \ \ \ \ fwrite(buf,\ len,\ 1,\ stdout);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00199}00199\ \ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00200}00200\ \ \ \ \ \ \ \ \ fflush(stdout);}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00201}00201\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00202}00202\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00203}00203\ \}}
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00204}00204\ }
\DoxyCodeLine{\Hypertarget{nonblocking__server__example_8c_source_l00205}00205\ \textcolor{comment}{/*\ vi:set\ ts=8\ sts=4\ sw=4:\ */}}

\end{DoxyCode}
