Files
epics-base/modules/libcom/RTEMS/rtems_util.c
Michael Davidsaver e34b6c5c0c Fix spelling in comments
Should be non-functional, except for some error message strings.
2021-08-29 07:27:50 -07: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 utility 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;
}