kopia lustrzana https://github.com/Hamlib/Hamlib
Change WSAStartup logic in network.c to better allow for errors.
WSAStartup should now get called once only and should be restarted if needed. https://github.com/Hamlib/Hamlib/issues/679pull/680/head
rodzic
1cfa4c205c
commit
ec68495bd3
|
@ -143,12 +143,24 @@ int network_open(hamlib_port_t *rp, int default_port)
|
|||
|
||||
#ifdef __MINGW32__
|
||||
WSADATA wsadata;
|
||||
int ret;
|
||||
|
||||
if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR)
|
||||
if (wsstarted == 0)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: error creating socket\n", __func__);
|
||||
ret = WSAStartup(MAKEWORD(1, 1), &wsadata);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
wsstarted = 1;
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: WSAStartup OK\n", __func__);
|
||||
}
|
||||
else
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: error creating socket, WSAStartup ret=%d\n",
|
||||
__func__, ret);
|
||||
RETURNFUNC(-RIG_EIO);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -347,20 +359,30 @@ void network_flush(hamlib_port_t *rp)
|
|||
//! @cond Doxygen_Suppress
|
||||
int network_close(hamlib_port_t *rp)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
ENTERFUNC;
|
||||
|
||||
if (rp->fd > 0)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
ret = closesocket(rp->fd);
|
||||
|
||||
if (--wsstarted)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
#else
|
||||
ret = close(rp->fd);
|
||||
#endif
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: close socket ret=%d\n", __func__, ret);
|
||||
rp->fd = 0;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
if (wsstarted)
|
||||
{
|
||||
ret = WSACleanup();
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: WSACleanup ret=%d\n", __func__, ret);
|
||||
wsstarted = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
RETURNFUNC(ret);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue