mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-07-04 15:29:30 +00:00
Using PPPoS on win32 blocked since read and write are used from 2 different threads and read blocked.
This commit is contained in:
parent
813b025f97
commit
92a32dbce4
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
/* If this is 1, use COMx (not working yet), if 0, use a pipe (default) */
|
/** If SIO_USE_COMPORT==1, use COMx, if 0, use a pipe (default) */
|
||||||
#if SIO_USE_COMPORT
|
#if SIO_USE_COMPORT
|
||||||
#define SIO_DEVICENAME "\\\\.\\COM"
|
#define SIO_DEVICENAME "\\\\.\\COM"
|
||||||
#else
|
#else
|
||||||
@ -57,6 +57,29 @@ static int sio_abort=0;
|
|||||||
#define SIO_DEBUG LWIP_DBG_OFF
|
#define SIO_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if SIO_USE_COMPORT
|
||||||
|
/** When using a real COM port, set up the
|
||||||
|
* serial line settings (baudrate etc.)
|
||||||
|
*/
|
||||||
|
static BOOL
|
||||||
|
sio_setup(HANDLE fd)
|
||||||
|
{
|
||||||
|
COMMTIMEOUTS cto;
|
||||||
|
memset(&cto, 0, sizeof(cto));
|
||||||
|
|
||||||
|
if(!GetCommTimeouts(fd, &cto))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
/* change read timeout, leave write timeout as it is */
|
||||||
|
cto.ReadIntervalTimeout = 1;
|
||||||
|
cto.ReadTotalTimeoutMultiplier = 0;
|
||||||
|
cto.ReadTotalTimeoutConstant = 100; /* 10 ms */
|
||||||
|
return SetCommTimeouts(fd, &cto);
|
||||||
|
/* @todo: set up baudrate and other communication settings */
|
||||||
|
}
|
||||||
|
#endif /* SIO_USE_COMPORT */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a serial device for communication.
|
* Opens a serial device for communication.
|
||||||
*
|
*
|
||||||
@ -65,15 +88,23 @@ static int sio_abort=0;
|
|||||||
*/
|
*/
|
||||||
sio_fd_t sio_open(u8_t devnum)
|
sio_fd_t sio_open(u8_t devnum)
|
||||||
{
|
{
|
||||||
HANDLE hPipe = INVALID_HANDLE_VALUE;
|
HANDLE fileHandle = INVALID_HANDLE_VALUE;
|
||||||
CHAR szPipeName[256];
|
CHAR fileName[256];
|
||||||
LWIP_DEBUGF(SIO_DEBUG, ("sio_open(%lu)\n", (DWORD)devnum));
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_open(%lu)\n", (DWORD)devnum));
|
||||||
sprintf(szPipeName, SIO_DEVICENAME"%lu", (DWORD)(devnum));
|
_snprintf(fileName, 255, SIO_DEVICENAME"%lu", (DWORD)(devnum));
|
||||||
hPipe = CreateFile(szPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
fileHandle = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (hPipe != INVALID_HANDLE_VALUE) {
|
if (fileHandle != INVALID_HANDLE_VALUE) {
|
||||||
sio_abort = 0;
|
sio_abort = 0;
|
||||||
FlushFileBuffers(hPipe);
|
FlushFileBuffers(fileHandle);
|
||||||
return (sio_fd_t)(hPipe);
|
#if SIO_USE_COMPORT
|
||||||
|
if(!sio_setup(fileHandle)) {
|
||||||
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_open(%lu): sio_setup. GetLastError() returns %d\n",
|
||||||
|
(DWORD)devnum, GetLastError()));
|
||||||
|
CloseHandle(fileHandle);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif /* SIO_USE_COMPORT */
|
||||||
|
return (sio_fd_t)(fileHandle);
|
||||||
}
|
}
|
||||||
LWIP_DEBUGF(SIO_DEBUG, ("sio_open(%lu) failed. GetLastError() returns %d\n",
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_open(%lu) failed. GetLastError() returns %d\n",
|
||||||
(DWORD)devnum, GetLastError()));
|
(DWORD)devnum, GetLastError()));
|
||||||
@ -126,10 +157,11 @@ u8_t sio_recv(sio_fd_t fd)
|
|||||||
*/
|
*/
|
||||||
u32_t sio_read(sio_fd_t fd, u8_t* data, u32_t len)
|
u32_t sio_read(sio_fd_t fd, u8_t* data, u32_t len)
|
||||||
{
|
{
|
||||||
|
BOOL ret;
|
||||||
DWORD dwNbBytesReadden = 0;
|
DWORD dwNbBytesReadden = 0;
|
||||||
LWIP_DEBUGF(SIO_DEBUG, ("sio_read()...\n"));
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_read()...\n"));
|
||||||
ReadFile((HANDLE)(fd), data, len, &dwNbBytesReadden, NULL);
|
ret = ReadFile((HANDLE)(fd), data, len, &dwNbBytesReadden, NULL);
|
||||||
LWIP_DEBUGF(SIO_DEBUG, ("sio_read()=%lu bytes\n", dwNbBytesReadden));
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_read()=%lu bytes -> \n", dwNbBytesReadden, ret));
|
||||||
return dwNbBytesReadden;
|
return dwNbBytesReadden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,10 +177,11 @@ u32_t sio_read(sio_fd_t fd, u8_t* data, u32_t len)
|
|||||||
*/
|
*/
|
||||||
u32_t sio_write(sio_fd_t fd, u8_t* data, u32_t len)
|
u32_t sio_write(sio_fd_t fd, u8_t* data, u32_t len)
|
||||||
{
|
{
|
||||||
|
BOOL ret;
|
||||||
DWORD dwNbBytesWritten = 0;
|
DWORD dwNbBytesWritten = 0;
|
||||||
LWIP_DEBUGF(SIO_DEBUG, ("sio_write()...\n"));
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_write()...\n"));
|
||||||
WriteFile((HANDLE)(fd), data, len, &dwNbBytesWritten, NULL);
|
ret = WriteFile((HANDLE)(fd), data, len, &dwNbBytesWritten, NULL);
|
||||||
LWIP_DEBUGF(SIO_DEBUG, ("sio_write()=%lu bytes\n", dwNbBytesWritten));
|
LWIP_DEBUGF(SIO_DEBUG, ("sio_write()=%lu bytes -> %d\n", dwNbBytesWritten, ret));
|
||||||
return dwNbBytesWritten;
|
return dwNbBytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +199,7 @@ void sio_read_abort(sio_fd_t fd)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @todo: remove this by changing the PPP log defines to use LWIP_DEBUGF()...
|
||||||
* Used by pppdebug:
|
* Used by pppdebug:
|
||||||
* ppp_trace - a form of printf to send tracing information to stderr
|
* ppp_trace - a form of printf to send tracing information to stderr
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user