Files
epics-base/modules/libcom/RTEMS/rtems_util.c
Andrew Johnson 3c99391d93 Added SPDX License ID to all EPICS-original source files
In some cases the license-identification header was missing,
so I added that as well. Replaced the remaining headers that
specifically identified "Versions 3.13.7 and higher".

Makefiles and the build system were deliberately excluded.
2020-08-03 11:53:01 -05:00

45 lines
1.4 KiB
C

/*************************************************************************\
* Copyright (c) 2002 The University of Saskatchewan
* SPDX-License-Identifier: EPICS
* EPICS Base is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* RTEMS utilitiy routines for EPICS
* Author: W. Eric Norum
* eric@cls.usask.ca
* (306) 966-6055
*
* Supplies routines that are present in vxWorks but missing in RTEMS.
*/
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
/*
* Like connect(), but with an explicit timeout
*/
int connectWithTimeout (int sfd,
struct sockaddr *addr,
int addrlen,
struct timeval *timeout)
{
struct timeval sv;
socklen_t svlen = sizeof sv;
int ret;
if (!timeout)
return connect (sfd, addr, addrlen);
if (getsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&sv, &svlen) < 0)
return -1;
if (setsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char *)timeout, sizeof *timeout) < 0)
return -1;
ret = connect (sfd, addr, addrlen);
setsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&sv, sizeof sv);
return ret;
}