accept_8c.tex
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
\hypertarget{accept_8c}{
\section{src/socket/accept.c File Reference}
\label{accept_8c}\index{src/socket/accept.c@{src/socket/accept.c}}
}
{\ttfamily \#include $<$errno.h$>$}\par
{\ttfamily \#include \char`\"{}socket.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}interface/class.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}interface/logger.h\char`\"{}}\par
Include dependency graph for accept.c:
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item
\hyperlink{structSock}{Sock} \hyperlink{accept_8c_a46aa6b495ccf752e844f93bf46c9edd6}{socketAccept} (\hyperlink{structSock}{Sock} this, char remoteAddr\mbox{[}16\mbox{]})
\end{DoxyCompactItemize}
\subsection{Function Documentation}
\hypertarget{accept_8c_a46aa6b495ccf752e844f93bf46c9edd6}{
\index{accept.c@{accept.c}!socketAccept@{socketAccept}}
\index{socketAccept@{socketAccept}!accept.c@{accept.c}}
\subsubsection[{socketAccept}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Sock} socketAccept (
\begin{DoxyParamCaption}
\item[{{\bf Sock}}]{this, }
\item[{char}]{remoteAddr\mbox{[}16\mbox{]}}
\end{DoxyParamCaption}
)}}
\label{accept_8c_a46aa6b495ccf752e844f93bf46c9edd6}
: Uhh, this is bad. we open a new socket additionally to the one we get from the accept call. i have to change the socket constructor to be able to create the data structure without creation of a socket at all. For now i simply close the socket here.... :D
: change port to remote port on success
Definition at line 8 of file accept.c.
\begin{DoxyCode}
{
Sock sock; /* Socket for client */
unsigned int len; /* Length of client address data structure */
/* Set the size of the in-out parameter */
len = sizeof(this->addr);
sock = new(Sock, this->log, this->port);
close(sock->handle);
/* Wait for a client to connect */
sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len);
if (-1 == sock->handle) {
loggerLog(this->log, LOGGER_WARNING,
"error accepting connection: %s", strerror(errno));
} else {
loggerLog(this->log, LOGGER_INFO,
"handling client %s\n", inet_ntoa((sock->addr).si
n_addr));
}
return sock;
}
\end{DoxyCode}
Here is the call graph for this function: