38 #include "blocxx/BLOCXX_config.h"
40 #if !defined(BLOCXX_WIN32)
62 #include <sys/types.h>
64 #include <sys/socket.h>
67 #include <arpa/inet.h>
70 #include <netinet/in.h>
77 namespace BLOCXX_NAMESPACE
100 , m_isConnected(false)
104 , m_recvTimeoutExprd(false)
107 , m_out(&m_streamBuf)
108 , m_inout(&m_streamBuf)
109 , m_recvTimeout(
Timeout::infinite)
110 , m_sendTimeout(
Timeout::infinite)
111 , m_connectTimeout(
Timeout::infinite)
113 m_out.exceptions(std::ios::badbit);
114 m_inout.exceptions(std::ios::badbit);
121 , m_isConnected(true)
125 , m_recvTimeoutExprd(false)
128 , m_out(&m_streamBuf)
129 , m_inout(&m_streamBuf)
130 , m_recvTimeout(
Timeout::infinite)
131 , m_sendTimeout(
Timeout::infinite)
132 , m_connectTimeout(
Timeout::infinite)
134 m_out.exceptions(std::ios::badbit);
135 m_inout.exceptions(std::ios::badbit);
153 , m_isConnected(false)
156 , m_peerAddress(addr)
157 , m_recvTimeoutExprd(false)
160 , m_out(&m_streamBuf)
161 , m_inout(&m_streamBuf)
162 , m_recvTimeout(
Timeout::infinite)
163 , m_sendTimeout(
Timeout::infinite)
164 , m_connectTimeout(
Timeout::infinite)
166 m_out.exceptions(std::ios::badbit);
167 m_inout.exceptions(std::ios::badbit);
203 int domain_type = PF_UNIX;
206 domain_type = PF_INET;
207 #ifdef BLOCXX_HAVE_IPV6
209 if( reinterpret_cast<const sockaddr*>(addr.
getInetAddress())->sa_family == AF_INET6)
211 domain_type = PF_INET6;
217 if (sockfd.
get() == -1)
220 "Failed to create a socket");
224 if (::fcntl(sockfd.
get(), F_SETFD, FD_CLOEXEC) == -1)
229 int flags = ::fcntl(sockfd.
get(), F_GETFL, 0);
230 ::fcntl(sockfd.
get(), F_SETFL, flags | O_NONBLOCK);
231 #if defined(BLOCXX_NCR)
237 if (errno != EINPROGRESS)
254 pipefd = lUPipe->getInputHandle();
259 sockSo.waitForWrite =
true;
290 if (selra.
size() == 2 && selra[1].readAvailable)
294 else if (selra[0].readAvailable || selra[0].writeAvailable)
298 #if defined(BLOCXX_NCR)
299 if (::getsockopt(sockfd.
get(), SOL_SOCKET, SO_ERROR, (
char*)&error, &len) < 0)
301 if (::getsockopt(sockfd.
get(), SOL_SOCKET, SO_ERROR, &error, &len) < 0)
305 "SocketBaseImpl::connect() getsockopt() failed");
311 "SocketBaseImpl::connect() failed");
319 ::fcntl(sockfd.
get(), F_SETFL, flags);
341 ofstream comboTraceFile(combofilename.
c_str(), std::ios::app);
348 comboTraceFile <<
Format(
"\n--->fd: %1 opened to \"%2\" at %3.%4 <---\n",
getfd(),
359 m_in.clear(ios::eofbit);
363 m_out.clear(ios::eofbit);
384 ofstream comboTraceFile(combofilename.
c_str(), std::ios::app);
391 comboTraceFile <<
"\n--->fd: " <<
getfd() <<
" closed at " << curDateTime.
toString(
"%X") <<
405 struct sockaddr *p_addr;
407 memset(&ss, 0,
sizeof(ss));
409 p_addr =
reinterpret_cast<struct sockaddr*
>(&ss);
410 if (getsockname(
m_sockfd, p_addr, &len) != -1)
414 memset(&ss, 0,
sizeof(ss));
416 if (getpeername(
m_sockfd, p_addr, &len) != -1)
427 memset(&addr, 0,
sizeof(addr));
429 if (getsockname(
m_sockfd, reinterpret_cast<struct sockaddr*>(&addr), &len) == -1)
441 bool isError =
false;
460 if (!traceFile.write(static_cast<const char*>(dataOut), rc))
466 ofstream comboTraceFile(combofilename.
c_str(), std::ios::app);
473 comboTraceFile <<
"\n--->fd: " <<
getfd() <<
" Out " << rc <<
" bytes at " << curDateTime.
toString(
"%X") <<
475 if (!comboTraceFile.write(static_cast<const char*>(dataOut), rc))
497 bool isError =
false;
507 rc =
readAux(dataIn, dataInLen);
516 if (!traceFile.write(reinterpret_cast<const char*>(dataIn), rc))
522 ofstream comboTraceFile(combofilename.
c_str(), std::ios::app);
529 comboTraceFile <<
"\n--->fd: " <<
getfd() <<
" In " << rc <<
" bytes at " << curDateTime.
toString(
"%X") <<
531 if (!comboTraceFile.write(reinterpret_cast<const char*>(dataIn), rc))
601 #endif // #if !defined(BLOCXX_WIN32)