\hypertarget{mdi__tcp_8c}{}\doxysection{/repo/build/\+M\+D\+I\+\_\+\+Library/\+M\+D\+I\+\_\+\+Library/mdi\+\_\+tcp.c File Reference}
\label{mdi__tcp_8c}\index{/repo/build/MDI\_Library/MDI\_Library/mdi\_tcp.c@{/repo/build/MDI\_Library/MDI\_Library/mdi\_tcp.c}}


T\+CP communication implementation.  


{\ttfamily \#include $<$netinet/in.\+h$>$}\newline
{\ttfamily \#include $<$sys/socket.\+h$>$}\newline
{\ttfamily \#include $<$netdb.\+h$>$}\newline
{\ttfamily \#include $<$unistd.\+h$>$}\newline
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$signal.\+h$>$}\newline
{\ttfamily \#include $<$errno.\+h$>$}\newline
{\ttfamily \#include \char`\"{}mdi.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}mdi\+\_\+tcp.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}mdi\+\_\+global.\+h\char`\"{}}\newline
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \mbox{\hyperlink{mdi__tcp_8c_a47630f8f823b92ad9333c3c5f130cf90}{sigint\+\_\+handler}} (int dummy)
\begin{DoxyCompactList}\small\item\em S\+I\+G\+I\+NT handler to ensure the socket is closed on termination. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_a9e92ddf39c6d6ba0f02ceaea23133f53}\label{mdi__tcp_8c_a9e92ddf39c6d6ba0f02ceaea23133f53}} 
int \mbox{\hyperlink{mdi__tcp_8c_a9e92ddf39c6d6ba0f02ceaea23133f53}{enable\+\_\+tcp\+\_\+support}} (int code\+\_\+id)
\begin{DoxyCompactList}\small\item\em Enable support for the T\+CP method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_ac2a9634d0b8e19bb873bf501ca72a04f}\label{mdi__tcp_8c_ac2a9634d0b8e19bb873bf501ca72a04f}} 
int \mbox{\hyperlink{mdi__tcp_8c_ac2a9634d0b8e19bb873bf501ca72a04f}{tcp\+\_\+on\+\_\+selection}} ()
\begin{DoxyCompactList}\small\item\em Callback when the end-\/user selects T\+CP as the method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_a9b8435f5033a5fd6a14310324854f7df}\label{mdi__tcp_8c_a9b8435f5033a5fd6a14310324854f7df}} 
int \mbox{\hyperlink{mdi__tcp_8c_a9b8435f5033a5fd6a14310324854f7df}{tcp\+\_\+on\+\_\+accept\+\_\+communicator}} ()
\begin{DoxyCompactList}\small\item\em Callback when the T\+CP method must accept a communicator. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_ab4cfd63fb562e43a1237fa229841c56c}\label{mdi__tcp_8c_ab4cfd63fb562e43a1237fa229841c56c}} 
int \mbox{\hyperlink{mdi__tcp_8c_ab4cfd63fb562e43a1237fa229841c56c}{tcp\+\_\+on\+\_\+send\+\_\+command}} (const char $\ast$command, M\+D\+I\+\_\+\+Comm comm, int $\ast$skip\+\_\+flag)
\begin{DoxyCompactList}\small\item\em Callback when the T\+CP method must send a command. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_a7a65b903a90360e2d1adef63e2e63aef}\label{mdi__tcp_8c_a7a65b903a90360e2d1adef63e2e63aef}} 
int \mbox{\hyperlink{mdi__tcp_8c_a7a65b903a90360e2d1adef63e2e63aef}{tcp\+\_\+after\+\_\+send\+\_\+command}} (const char $\ast$command, M\+D\+I\+\_\+\+Comm comm)
\begin{DoxyCompactList}\small\item\em Callback after the T\+CP method has received a command. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_a10fd67e4f26f799e0f5c6b45782a4a6d}\label{mdi__tcp_8c_a10fd67e4f26f799e0f5c6b45782a4a6d}} 
int \mbox{\hyperlink{mdi__tcp_8c_a10fd67e4f26f799e0f5c6b45782a4a6d}{tcp\+\_\+on\+\_\+recv\+\_\+command}} (M\+D\+I\+\_\+\+Comm comm)
\begin{DoxyCompactList}\small\item\em Callback when the T\+CP method must receive a command. \end{DoxyCompactList}\item 
int \mbox{\hyperlink{mdi__tcp_8c_a5a88b9f08abe704bafbcb4e6f6768ed6}{tcp\+\_\+listen}} (int port\+\_\+in)
\begin{DoxyCompactList}\small\item\em Begin listening for incoming T\+CP connections. \end{DoxyCompactList}\item 
int \mbox{\hyperlink{mdi__tcp_8c_a4e01d97465e426f6fbbe98f3f6eba4de}{tcp\+\_\+request\+\_\+connection}} (int port\+\_\+in, char $\ast$hostname\+\_\+ptr)
\begin{DoxyCompactList}\small\item\em Request a connection over T\+CP. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{mdi__tcp_8c_ad9d6ed32787d7fb6cd0a555fd8b63b91}\label{mdi__tcp_8c_ad9d6ed32787d7fb6cd0a555fd8b63b91}} 
int \mbox{\hyperlink{mdi__tcp_8c_ad9d6ed32787d7fb6cd0a555fd8b63b91}{tcp\+\_\+accept\+\_\+connection}} ()
\begin{DoxyCompactList}\small\item\em Accept a T\+CP connection request. \end{DoxyCompactList}\item 
int \mbox{\hyperlink{mdi__tcp_8c_a813e2b1b10b9c069227b6a4afac0e2ed}{tcp\+\_\+send}} (const void $\ast$buf, int count, M\+D\+I\+\_\+\+Datatype datatype, M\+D\+I\+\_\+\+Comm comm, int msg\+\_\+flag)
\begin{DoxyCompactList}\small\item\em Send data through an M\+DI connection, using T\+CP. \end{DoxyCompactList}\item 
int \mbox{\hyperlink{mdi__tcp_8c_a1debb8c0b825d277a70db864450d1ac0}{tcp\+\_\+recv}} (void $\ast$buf, int count, M\+D\+I\+\_\+\+Datatype datatype, M\+D\+I\+\_\+\+Comm comm, int msg\+\_\+flag)
\begin{DoxyCompactList}\small\item\em Receive data through an M\+DI connection, using T\+CP. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
T\+CP communication implementation. 



\doxysubsection{Function Documentation}
\mbox{\Hypertarget{mdi__tcp_8c_a47630f8f823b92ad9333c3c5f130cf90}\label{mdi__tcp_8c_a47630f8f823b92ad9333c3c5f130cf90}} 
\index{mdi\_tcp.c@{mdi\_tcp.c}!sigint\_handler@{sigint\_handler}}
\index{sigint\_handler@{sigint\_handler}!mdi\_tcp.c@{mdi\_tcp.c}}
\doxysubsubsection{\texorpdfstring{sigint\_handler()}{sigint\_handler()}}
{\footnotesize\ttfamily void sigint\+\_\+handler (\begin{DoxyParamCaption}\item[{int}]{dummy }\end{DoxyParamCaption})}



S\+I\+G\+I\+NT handler to ensure the socket is closed on termination. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em dummy} & Dummy argument. \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{mdi__tcp_8c_a5a88b9f08abe704bafbcb4e6f6768ed6}\label{mdi__tcp_8c_a5a88b9f08abe704bafbcb4e6f6768ed6}} 
\index{mdi\_tcp.c@{mdi\_tcp.c}!tcp\_listen@{tcp\_listen}}
\index{tcp\_listen@{tcp\_listen}!mdi\_tcp.c@{mdi\_tcp.c}}
\doxysubsubsection{\texorpdfstring{tcp\_listen()}{tcp\_listen()}}
{\footnotesize\ttfamily int tcp\+\_\+listen (\begin{DoxyParamCaption}\item[{int}]{port\+\_\+in }\end{DoxyParamCaption})}



Begin listening for incoming T\+CP connections. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em port} & Port to listen over \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{mdi__tcp_8c_a1debb8c0b825d277a70db864450d1ac0}\label{mdi__tcp_8c_a1debb8c0b825d277a70db864450d1ac0}} 
\index{mdi\_tcp.c@{mdi\_tcp.c}!tcp\_recv@{tcp\_recv}}
\index{tcp\_recv@{tcp\_recv}!mdi\_tcp.c@{mdi\_tcp.c}}
\doxysubsubsection{\texorpdfstring{tcp\_recv()}{tcp\_recv()}}
{\footnotesize\ttfamily int tcp\+\_\+recv (\begin{DoxyParamCaption}\item[{void $\ast$}]{buf,  }\item[{int}]{count,  }\item[{M\+D\+I\+\_\+\+Datatype}]{datatype,  }\item[{M\+D\+I\+\_\+\+Comm}]{comm,  }\item[{int}]{msg\+\_\+flag }\end{DoxyParamCaption})}



Receive data through an M\+DI connection, using T\+CP. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em buf} & Pointer to the buffer where the received data will be stored. \\
\hline
\mbox{\texttt{ in}}  & {\em count} & Number of values (integers, double precision floats, characters, etc.) to be received. \\
\hline
\mbox{\texttt{ in}}  & {\em datatype} & M\+DI handle (M\+D\+I\+\_\+\+I\+NT, M\+D\+I\+\_\+\+D\+O\+U\+B\+LE, M\+D\+I\+\_\+\+C\+H\+AR, etc.) corresponding to the type of data to be received. \\
\hline
\mbox{\texttt{ in}}  & {\em comm} & M\+DI communicator associated with the connection to the sending code. \\
\hline
\mbox{\texttt{ in}}  & {\em msg\+\_\+flag} & Type of role this data has within a message. 0\+: Not part of a message. 1\+: The header of a message. 2\+: The body (data) of a message. \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{mdi__tcp_8c_a4e01d97465e426f6fbbe98f3f6eba4de}\label{mdi__tcp_8c_a4e01d97465e426f6fbbe98f3f6eba4de}} 
\index{mdi\_tcp.c@{mdi\_tcp.c}!tcp\_request\_connection@{tcp\_request\_connection}}
\index{tcp\_request\_connection@{tcp\_request\_connection}!mdi\_tcp.c@{mdi\_tcp.c}}
\doxysubsubsection{\texorpdfstring{tcp\_request\_connection()}{tcp\_request\_connection()}}
{\footnotesize\ttfamily int tcp\+\_\+request\+\_\+connection (\begin{DoxyParamCaption}\item[{int}]{port\+\_\+in,  }\item[{char $\ast$}]{hostname\+\_\+ptr }\end{DoxyParamCaption})}



Request a connection over T\+CP. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em port} & Port over which the driver is listening \\
\hline
\mbox{\texttt{ in}}  & {\em hostname\+\_\+ptr} & Hostname of the driver \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{mdi__tcp_8c_a813e2b1b10b9c069227b6a4afac0e2ed}\label{mdi__tcp_8c_a813e2b1b10b9c069227b6a4afac0e2ed}} 
\index{mdi\_tcp.c@{mdi\_tcp.c}!tcp\_send@{tcp\_send}}
\index{tcp\_send@{tcp\_send}!mdi\_tcp.c@{mdi\_tcp.c}}
\doxysubsubsection{\texorpdfstring{tcp\_send()}{tcp\_send()}}
{\footnotesize\ttfamily int tcp\+\_\+send (\begin{DoxyParamCaption}\item[{const void $\ast$}]{buf,  }\item[{int}]{count,  }\item[{M\+D\+I\+\_\+\+Datatype}]{datatype,  }\item[{M\+D\+I\+\_\+\+Comm}]{comm,  }\item[{int}]{msg\+\_\+flag }\end{DoxyParamCaption})}



Send data through an M\+DI connection, using T\+CP. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em buf} & Pointer to the data to be sent. \\
\hline
\mbox{\texttt{ in}}  & {\em count} & Number of values (integers, double precision floats, characters, etc.) to be sent. \\
\hline
\mbox{\texttt{ in}}  & {\em datatype} & M\+DI handle (M\+D\+I\+\_\+\+I\+NT, M\+D\+I\+\_\+\+D\+O\+U\+B\+LE, M\+D\+I\+\_\+\+C\+H\+AR, etc.) corresponding to the type of data to be sent. \\
\hline
\mbox{\texttt{ in}}  & {\em comm} & M\+DI communicator associated with the intended recipient code. \\
\hline
\mbox{\texttt{ in}}  & {\em msg\+\_\+flag} & Type of role this data has within a message. 0\+: Not part of a message. 1\+: The header of a message. 2\+: The body (data) of a message. \\
\hline
\end{DoxyParams}
