improved the way that socket error numbers are converted to strings
and cleaned up the osiMutex class
This commit is contained in:
@@ -43,7 +43,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
@@ -51,7 +51,7 @@ typedef int osiSockIoctl_t;
|
||||
|
||||
#define FD_IN_FDSET(FD) ((FD)<FD_SETSIZE)
|
||||
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
|
||||
#define SOCK_EWOULDBLOCK EWOULDBLOCK
|
||||
#define SOCK_ENOBUFS ENOBUFS
|
||||
|
||||
@@ -13,7 +13,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define SOCKERRNO WSAGetLastError()
|
||||
#define SOCKERRSTR getLastWSAErrorAsString()
|
||||
#define SOCKERRSTR(ERRNO_IN) convertSocketErrorToString(ERRNO_IN)
|
||||
|
||||
#define socket_close(S) closesocket(S)
|
||||
#define socket_ioctl(A,B,C) ioctlsocket(A,B,C)
|
||||
|
||||
@@ -38,9 +38,9 @@ int sethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -34,9 +34,9 @@ int sethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -40,9 +40,9 @@ int sethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -39,7 +39,7 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -39,7 +39,7 @@ int sethostname(char *name, int namelen);
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -102,7 +102,7 @@ int gethostname (char *name, int namelen);
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -125,13 +125,8 @@ typedef int osiSockIoctl_t;
|
||||
# define SOCKERRNO errno /* UCX and others? */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* !! this is no doubt incorrect !!
|
||||
* (error messages will be confusing until
|
||||
* this is fixed)
|
||||
*/
|
||||
#define SOCKERRSTR (strerror(SOCKERRNO))
|
||||
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
|
||||
#define MAXHOSTNAMELEN 75
|
||||
|
||||
#define SOCK_EWOULDBLOCK EWOULDBLOCK
|
||||
|
||||
@@ -3,50 +3,21 @@
|
||||
// osiMutex - OS independent mutex
|
||||
// (vxWorks version)
|
||||
//
|
||||
//
|
||||
// NOTES:
|
||||
// 1) epicsPrintf() is used in this file because we cant stand
|
||||
// the logMsg() 8 arg API amd we dont want the messages from different
|
||||
// tasks to co-mingle
|
||||
//
|
||||
|
||||
#include <semLib.h>
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsPrint.h>
|
||||
|
||||
#define DEBUG_OSIMUTEX
|
||||
|
||||
#ifdef DEBUG_OSIMUTEX
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_OSIMUTEX
|
||||
#define osiLock() osiLockI (__FILE__, __LINE__)
|
||||
#define osiUnlock() osiUnlockI (__FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
class osiMutex {
|
||||
public:
|
||||
class osiMutexNoMemory {}
|
||||
|
||||
osiMutex()
|
||||
{
|
||||
mutex = NULL;
|
||||
}
|
||||
//
|
||||
// constructor that returns status
|
||||
// (since g++ does not have exceptions)
|
||||
//
|
||||
int init ()
|
||||
{
|
||||
this->mutex = semMCreate(SEM_Q_PRIORITY|SEM_INVERSION_SAFE|SEM_DELETE_SAFE);
|
||||
if (this->mutex==NULL)
|
||||
{
|
||||
return -1;
|
||||
throw osiMutexNoMemory();
|
||||
}
|
||||
# ifdef DEBUG_OSIMUTEX
|
||||
epicsPrintf("created mutex at %lx\n",
|
||||
(unsigned long) this->mutex);
|
||||
# endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
~osiMutex()
|
||||
@@ -54,73 +25,27 @@ public:
|
||||
STATUS s;
|
||||
s = semDelete (this->mutex);
|
||||
assert (s==OK);
|
||||
# ifdef DEBUG_OSIMUTEX
|
||||
epicsPrintf("destroyed mutex at %lx\n",
|
||||
(unsigned long) this->mutex);
|
||||
# endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_OSIMUTEX
|
||||
void osiLockI(const char *pFN, unsigned ln)
|
||||
#else
|
||||
void osiLock()
|
||||
#endif
|
||||
void lock () const
|
||||
{
|
||||
STATUS s;
|
||||
if (!this->mutex) {
|
||||
# ifdef DEBUG_OSIMUTEX
|
||||
epicsPrintf(
|
||||
"osiMutex: lock request before init was ignored from %s at %u\n",
|
||||
pFN, ln);
|
||||
# else
|
||||
epicsPrintf(
|
||||
"osiMutex: lock request before init was ignored\n");
|
||||
# endif
|
||||
return;
|
||||
}
|
||||
assert(this->mutex);
|
||||
s = semTake (this->mutex, WAIT_FOREVER);
|
||||
assert (s==OK);
|
||||
# ifdef DEBUG_OSIMUTEX
|
||||
epicsPrintf("L%lx in %s at %u\n",
|
||||
(unsigned long) this->mutex,
|
||||
pFN, ln);
|
||||
# endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_OSIMUTEX
|
||||
void osiUnlockI(const char *pFN, unsigned ln)
|
||||
#else
|
||||
void osiUnlock()
|
||||
#endif
|
||||
void unlock() const
|
||||
{
|
||||
STATUS s;
|
||||
|
||||
if (!this->mutex) {
|
||||
# ifdef DEBUG_OSIMUTEX
|
||||
epicsPrintf(
|
||||
"osiMutex: unlock request before init was ignored from %s at %u\n",
|
||||
pFN, ln);
|
||||
# else
|
||||
epicsPrintf(
|
||||
"osiMutex: unlock request before init was ignored\n");
|
||||
# endif
|
||||
return;
|
||||
}
|
||||
s = semGive (this->mutex);
|
||||
assert (s==OK);
|
||||
# ifdef DEBUG_OSIMUTEX
|
||||
epicsPrintf("U%lx in %s at %d\n",
|
||||
(unsigned long) this->mutex,
|
||||
pFN, ln);
|
||||
# endif
|
||||
}
|
||||
|
||||
void show(unsigned level) const
|
||||
void show (unsigned level) const
|
||||
{
|
||||
semShow(this->mutex, (int) level);
|
||||
semShow (this->mutex, (int) level);
|
||||
}
|
||||
private:
|
||||
SEM_ID mutex;
|
||||
mutable SEM_ID mutex;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(SOCKERRNO))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
/*
|
||||
* it is quite lame on WRS's part to assume that
|
||||
|
||||
@@ -13,14 +13,10 @@
|
||||
//
|
||||
class osiMutex {
|
||||
public:
|
||||
//
|
||||
// constructor that returns status
|
||||
// (since g++ does not have exceptions)
|
||||
//
|
||||
int init() {return 0;}
|
||||
void osiLock() const {}
|
||||
void osiUnlock() const {}
|
||||
void show (unsigned) const {}
|
||||
class osiMutexNoMemory {};
|
||||
void lock () const {}
|
||||
void unlock () const {}
|
||||
void show (unsigned) const {}
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
@@ -51,7 +51,7 @@ typedef int osiSockIoctl_t;
|
||||
|
||||
#define FD_IN_FDSET(FD) ((FD)<FD_SETSIZE)
|
||||
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
|
||||
#define SOCK_EWOULDBLOCK EWOULDBLOCK
|
||||
#define SOCK_ENOBUFS ENOBUFS
|
||||
|
||||
@@ -125,13 +125,8 @@ typedef int osiSockIoctl_t;
|
||||
# define SOCKERRNO errno /* UCX and others? */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* !! this is no doubt incorrect !!
|
||||
* (error messages will be confusing until
|
||||
* this is fixed)
|
||||
*/
|
||||
#define SOCKERRSTR (strerror(SOCKERRNO))
|
||||
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
|
||||
#define MAXHOSTNAMELEN 75
|
||||
|
||||
#define SOCK_EWOULDBLOCK EWOULDBLOCK
|
||||
|
||||
@@ -13,7 +13,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define SOCKERRNO WSAGetLastError()
|
||||
#define SOCKERRSTR getLastWSAErrorAsString()
|
||||
#define SOCKERRSTR(ERRNO_IN) convertSocketErrorToString(ERRNO_IN)
|
||||
|
||||
#define socket_close(S) closesocket(S)
|
||||
#define socket_ioctl(A,B,C) ioctlsocket(A,B,C)
|
||||
|
||||
@@ -38,9 +38,9 @@ int sethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -34,9 +34,9 @@ int sethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -40,9 +40,9 @@ int sethostname(char *name, int namelen);
|
||||
#endif
|
||||
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -39,7 +39,7 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -39,7 +39,7 @@ int sethostname(char *name, int namelen);
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -102,7 +102,7 @@ int gethostname (char *name, int namelen);
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(errno))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
@@ -28,7 +28,7 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define SOCKERRSTR (strerror(SOCKERRNO))
|
||||
#define SOCKERRSTR(ERRNO_IN) (strerror(ERRNO_IN))
|
||||
#define socket_close(S) close(S)
|
||||
/*
|
||||
* it is quite lame on WRS's part to assume that
|
||||
|
||||
Reference in New Issue
Block a user