Commit 0964495b authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

- Don't use event flags with ReadFileEx and WriteFileEx.

- Use overlapped structure with WriteFile, since FILE_FLAG_OVERLAPPED is specified. - Cancel overlapped operations in CloseComm.
parent 5016e921
...@@ -259,9 +259,16 @@ static VOID WINAPI COMM16_ReadComplete(DWORD status, DWORD len, LPOVERLAPPED ov) ...@@ -259,9 +259,16 @@ static VOID WINAPI COMM16_ReadComplete(DWORD status, DWORD len, LPOVERLAPPED ov)
} }
ptr = &COM[cid]; ptr = &COM[cid];
/* we get cancelled when CloseComm is called */
if (status==STATUS_CANCELLED)
{
TRACE("Cancelled\n");
return;
}
/* read data from comm port */ /* read data from comm port */
if (status != STATUS_SUCCESS) { if (status != STATUS_SUCCESS) {
ERR("async read failed\n"); ERR("async read failed %08lx\n",status);
COM[cid].commerror = CE_RXOVER; COM[cid].commerror = CE_RXOVER;
return; return;
} }
...@@ -303,6 +310,29 @@ static VOID WINAPI COMM16_ReadComplete(DWORD status, DWORD len, LPOVERLAPPED ov) ...@@ -303,6 +310,29 @@ static VOID WINAPI COMM16_ReadComplete(DWORD status, DWORD len, LPOVERLAPPED ov)
comm_waitread(ptr); comm_waitread(ptr);
} }
/* this is meant to work like write() */
static INT COMM16_WriteFile(HANDLE hComm, LPCVOID buffer, DWORD len)
{
OVERLAPPED ov;
DWORD count= -1;
ZeroMemory(&ov,sizeof ov);
ov.hEvent = CreateEventA(NULL,0,0,NULL);
if(ov.hEvent==INVALID_HANDLE_VALUE)
return -1;
if(!WriteFile(hComm,buffer,len,&count,&ov))
{
if(GetLastError()==ERROR_IO_PENDING)
{
GetOverlappedResult(hComm,&ov,&count,TRUE);
}
}
CloseHandle(ov.hEvent);
return count;
}
static VOID WINAPI COMM16_WriteComplete(DWORD status, DWORD len, LPOVERLAPPED ov) static VOID WINAPI COMM16_WriteComplete(DWORD status, DWORD len, LPOVERLAPPED ov)
{ {
int prev, bleft; int prev, bleft;
...@@ -332,8 +362,7 @@ static VOID WINAPI COMM16_WriteComplete(DWORD status, DWORD len, LPOVERLAPPED ov ...@@ -332,8 +362,7 @@ static VOID WINAPI COMM16_WriteComplete(DWORD status, DWORD len, LPOVERLAPPED ov
/* write any TransmitCommChar character */ /* write any TransmitCommChar character */
if (ptr->xmit>=0) { if (ptr->xmit>=0) {
if(!WriteFile(ptr->handle, &(ptr->xmit), 1, &len, NULL)) len = COMM16_WriteFile(ptr->handle, &(ptr->xmit), 1);
len = -1;
if (len > 0) ptr->xmit = -1; if (len > 0) ptr->xmit = -1;
} }
...@@ -564,8 +593,6 @@ INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue) ...@@ -564,8 +593,6 @@ INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
ZeroMemory(&COM[port].read_ov,sizeof (OVERLAPPED)); ZeroMemory(&COM[port].read_ov,sizeof (OVERLAPPED));
ZeroMemory(&COM[port].write_ov,sizeof (OVERLAPPED)); ZeroMemory(&COM[port].write_ov,sizeof (OVERLAPPED));
COM[port].read_ov.hEvent = CreateEventA(NULL,0,0,NULL);
COM[port].write_ov.hEvent = CreateEventA(NULL,0,0,NULL);
comm_waitread( &COM[port] ); comm_waitread( &COM[port] );
USER16_AlertableWait++; USER16_AlertableWait++;
...@@ -611,9 +638,8 @@ INT16 WINAPI CloseComm16(INT16 cid) ...@@ -611,9 +638,8 @@ INT16 WINAPI CloseComm16(INT16 cid)
if (!(cid&FLAG_LPT)) { if (!(cid&FLAG_LPT)) {
/* COM port */ /* COM port */
UnMapLS( COM[cid].seg_unknown ); UnMapLS( COM[cid].seg_unknown );
CloseHandle(COM[cid].read_ov.hEvent);
CloseHandle(COM[cid].write_ov.hEvent);
USER16_AlertableWait--; USER16_AlertableWait--;
CancelIo(ptr->handle);
/* free buffers */ /* free buffers */
free(ptr->outbuf); free(ptr->outbuf);
...@@ -793,14 +819,9 @@ INT16 WINAPI GetCommError16(INT16 cid,LPCOMSTAT16 lpStat) ...@@ -793,14 +819,9 @@ INT16 WINAPI GetCommError16(INT16 cid,LPCOMSTAT16 lpStat)
COMM_MSRUpdate( ptr->handle, stol ); COMM_MSRUpdate( ptr->handle, stol );
if (lpStat) { if (lpStat) {
HANDLE rw_events[2];
lpStat->status = 0; lpStat->status = 0;
rw_events[0] = COM[cid].read_ov.hEvent; WaitForMultipleObjectsEx(0,NULL,FALSE,1,TRUE);
rw_events[1] = COM[cid].write_ov.hEvent;
WaitForMultipleObjectsEx(2,&rw_events[0],FALSE,1,TRUE);
lpStat->cbOutQue = comm_outbuf(ptr); lpStat->cbOutQue = comm_outbuf(ptr);
lpStat->cbInQue = comm_inbuf(ptr); lpStat->cbInQue = comm_inbuf(ptr);
...@@ -1002,8 +1023,8 @@ INT16 WINAPI TransmitCommChar16(INT16 cid,CHAR chTransmit) ...@@ -1002,8 +1023,8 @@ INT16 WINAPI TransmitCommChar16(INT16 cid,CHAR chTransmit)
if (ptr->obuf_head == ptr->obuf_tail) { if (ptr->obuf_head == ptr->obuf_tail) {
/* transmit queue empty, try to transmit directly */ /* transmit queue empty, try to transmit directly */
DWORD len; if(1!=COMM16_WriteFile(ptr->handle, &chTransmit, 1))
if(!WriteFile(ptr->handle, &chTransmit, 1, &len, NULL)) { {
/* didn't work, queue it */ /* didn't work, queue it */
ptr->xmit = chTransmit; ptr->xmit = chTransmit;
comm_waitwrite(ptr); comm_waitwrite(ptr);
...@@ -1070,7 +1091,7 @@ INT16 WINAPI ReadComm16(INT16 cid,LPSTR lpvBuf,INT16 cbRead) ...@@ -1070,7 +1091,7 @@ INT16 WINAPI ReadComm16(INT16 cid,LPSTR lpvBuf,INT16 cbRead)
} }
if(0==comm_inbuf(ptr)) if(0==comm_inbuf(ptr))
WaitForSingleObjectEx( COM[cid].read_ov.hEvent, 1, TRUE); WaitForMultipleObjectsEx(0,NULL,FALSE,1,TRUE);
/* read unget character */ /* read unget character */
if (ptr->unget>=0) { if (ptr->unget>=0) {
...@@ -1128,8 +1149,7 @@ INT16 WINAPI WriteComm16(INT16 cid, LPSTR lpvBuf, INT16 cbWrite) ...@@ -1128,8 +1149,7 @@ INT16 WINAPI WriteComm16(INT16 cid, LPSTR lpvBuf, INT16 cbWrite)
while (length < cbWrite) { while (length < cbWrite) {
if ((ptr->obuf_head == ptr->obuf_tail) && (ptr->xmit < 0)) { if ((ptr->obuf_head == ptr->obuf_tail) && (ptr->xmit < 0)) {
/* no data queued, try to write directly */ /* no data queued, try to write directly */
if(!WriteFile(ptr->handle, lpvBuf, cbWrite - length, (LPDWORD)&status, NULL)) status = COMM16_WriteFile(ptr->handle, lpvBuf, cbWrite - length);
status = -1;
if (status > 0) { if (status > 0) {
lpvBuf += status; lpvBuf += status;
length += status; length += status;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment