19 #ifdef TGT_OS_TYPE_VXWORKS
32 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
33 #include <sys/socket.h>
37 #include <arpa/inet.h>
39 #error OS not supported for IP Socket Communications
59 ,m_timeoutMicroseconds(0)
72 const U32 timeout_seconds,
73 const U32 timeout_microseconds
107 status = this->openProtocol(SOCK_STREAM);
130 struct sockaddr_in address;
141 if ((socketFd = ::socket(AF_INET, protocol, 0)) == -1) {
145 address.sin_family = AF_INET;
146 address.sin_port = htons(this->
m_port);
147 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN
148 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
151 #ifdef TGT_OS_TYPE_VXWORKS
152 address.sin_addr.s_addr = inet_addr(this->
m_hostname);
155 struct timeval timeout;
159 if (setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, (
char *)&timeout,
sizeof(timeout)) < 0) {
160 (void) ::
close(socketFd);
164 struct hostent *host_entry;
165 if ((host_entry = gethostbyname(this->
m_hostname)) ==
NULL || host_entry->h_addr_list[0] ==
NULL) {
170 if (inet_pton(address.sin_family,
m_hostname, &(address.sin_addr)) < 0) {
176 if (protocol != SOCK_DGRAM && connect(socketFd,
reinterpret_cast<struct sockaddr *
>(&address),
177 sizeof(address)) < 0) {
182 else if (protocol == SOCK_DGRAM) {
184 memcpy(&this->
m_state->
m_udpAddr, &address,
sizeof(this->m_state->m_udpAddr));
194 reinterpret_cast<POINTER_CAST
>(
isInput ?
"uplink" :
"downlink"),
195 reinterpret_cast<POINTER_CAST
>((protocol == SOCK_DGRAM) ?
"udp" :
"tcp"));
213 reinterpret_cast<struct sockaddr *
>(&this->
m_state->
m_udpAddr),
sizeof(this->m_state->m_udpAddr));
220 if (sent == -1 && errno == EINTR) {
224 else if (sent == -1 && errno == EBADF) {
231 else if (sent == -1 && errno == EINTR) {
249 if (size == -1 && errno != EINTR && errno != ECONNRESET) {
254 else if (size == -1 && errno == EINTR) {
258 else if (size == 0 || errno == ECONNRESET) {