using namespace std;
using namespace PLATFORM;
+inline bool RemoveLock(const char *strDeviceName)
+{
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
+ return dev_unlock(strDeviceName, 0) == 0;
+ #endif
+}
+
void CSerialSocket::Close(void)
{
if (IsOpen())
{
SocketClose(m_socket);
- #if !defined(__APPLE__) && !defined(__FreeBSD__)
- dev_unlock(m_strName.c_str(), m_lockPid);
- #endif
+ RemoveLock(m_strName.c_str());
}
}
if (IsOpen())
{
SocketClose(m_socket);
- #if !defined(__APPLE__) && !defined(__FreeBSD__)
- dev_unlock(m_strName.c_str(), m_lockPid);
- #endif
+ RemoveLock(m_strName.c_str());
}
}
}
#if !defined(__APPLE__) && !defined(__FreeBSD__)
- m_lockPid = dev_lock(m_strName.c_str());
- if (m_lockPid != 0)
+ if (dev_lock(m_strName.c_str()) != 0)
{
m_strError = "Couldn't lock the serial port";
m_iError = EBUSY;
if (m_socket == INVALID_SERIAL_SOCKET_VALUE)
{
m_strError = strerror(errno);
- #if !defined(__APPLE__) && !defined(__FreeBSD__)
- m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid);
- #endif
+ RemoveLock(m_strName.c_str());
return false;
}
if (tcsetattr(m_socket, TCSANOW, &m_options) != 0)
{
m_strError = strerror(errno);
- #if !defined(__APPLE__) && !defined(__FreeBSD__)
- m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid);
- #endif
+ RemoveLock(m_strName.c_str());
return false;
}
CCommonSocket<serial_socket_t>(INVALID_SERIAL_SOCKET_VALUE, strName),
#ifdef __WINDOWS__
m_iCurrentReadTimeout(MAXDWORD),
- #else
- m_lockPid(0),
#endif
m_bIsOpen(false),
m_iBaudrate(iBaudrate),
protected:
#ifndef __WINDOWS__
struct termios m_options;
- pid_t m_lockPid;
#else
bool SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeoutMs);
DWORD m_iCurrentReadTimeout;