Skip to content

Commit

Permalink
posix: warn on epicsSocketCreate() without osiSockAttach()
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Dec 22, 2023
1 parent c75b9ad commit 07cbf00
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions modules/libcom/src/osi/os/posix/osdSock.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "osiSock.h"
#include "epicsAssert.h"
#include "errlog.h"
#include "epicsAtomic.h"

/* Linux and *BSD (at least) specific way to atomically set O_CLOEXEC.
* RTEMS 5.1 provides SOCK_CLOEXEC, but doesn't implement accept4()
Expand Down Expand Up @@ -60,19 +61,18 @@ static void unlockInfo (void)
epicsMutexUnlock (infoMutex);
}

/*
* NOOP
*/

static size_t nAttached;

int osiSockAttach()
{
epicsAtomicIncrSizeT(&nAttached);
return 1;
}

/*
* NOOP
*/
void osiSockRelease()
{
epicsAtomicDecrSizeT(&nAttached);
}

/*
Expand All @@ -83,6 +83,11 @@ void osiSockRelease()
LIBCOM_API SOCKET epicsStdCall epicsSocketCreate (
int domain, int type, int protocol )
{
static unsigned char warnAttached;
if(!epicsAtomicGetSizeT(&nAttached) && !warnAttached) {
warnAttached = 1;
errlogPrintf(ERL_WARNING ": epicsSocketCreate() without osiSockAttach() is not portable\n");
}
SOCKET sock = socket ( domain, type | SOCK_CLOEXEC, protocol );
if ( sock < 0 ) {
sock = INVALID_SOCKET;
Expand Down

0 comments on commit 07cbf00

Please sign in to comment.