[PATCH] [Kernel32]: ClearCommErrors
Eric Pouech
eric.pouech at wanadoo.fr
Fri Feb 24 14:12:43 CST 2006
- removed erroneous error handling in kernel32 comm implementation
- removed now unused server requests
The test on ClearCommError shows (tested on WinXP and 98 - thanks Jacek &
Vitaly) that Wine is doing something wrong. Moreover, the NTDLL interface
doesn't allow to implement Wine's current behavior.
So the conclusion is that ClearCommError should only deal with
*communication* errors (are being seen on the serial interface) rather
than API errors (which can be reported to the caller by the API itself).
I then removed all the stuff related to story the error status in the
server object.
A+
---
dlls/kernel/comm.c | 55 +++-------------------------------------------
dlls/kernel/tests/comm.c | 22 +++++++++++++++++-
server/protocol.def | 3 ---
server/serial.c | 11 ---------
4 files changed, 23 insertions(+), 68 deletions(-)
diff --git a/dlls/kernel/comm.c b/dlls/kernel/comm.c
index 326ef47..54c461c 100644
--- a/dlls/kernel/comm.c
+++ b/dlls/kernel/comm.c
@@ -650,39 +650,6 @@ BOOL WINAPI BuildCommDCBW(
return BuildCommDCBAndTimeoutsW(devid,lpdcb,NULL);
}
-static BOOL COMM_SetCommError(HANDLE handle, DWORD error)
-{
- DWORD ret;
-
- SERVER_START_REQ( set_serial_info )
- {
- req->handle = handle;
- req->flags = SERIALINFO_SET_ERROR;
- req->commerror = error;
- ret = !wine_server_call_err( req );
- }
- SERVER_END_REQ;
- return ret;
-}
-
-static BOOL COMM_GetCommError(HANDLE handle, LPDWORD lperror)
-{
- DWORD ret;
-
- if(!lperror)
- return FALSE;
-
- SERVER_START_REQ( get_serial_info )
- {
- req->handle = handle;
- ret = !wine_server_call_err( req );
- *lperror = reply->commerror;
- }
- SERVER_END_REQ;
-
- return ret;
-}
-
/*****************************************************************************
* SetCommBreak (KERNEL32.@)
*
@@ -750,7 +717,6 @@ BOOL WINAPI EscapeCommFunction(
if(fd<0) return FALSE;
if (tcgetattr(fd,&port) == -1) {
- COMM_SetCommError(handle,CE_IOE);
release_comm_fd( handle, fd );
return FALSE;
}
@@ -824,7 +790,6 @@ BOOL WINAPI EscapeCommFunction(
if (!direct)
if (tcsetattr(fd, TCSADRAIN, &port) == -1) {
release_comm_fd( handle, fd );
- COMM_SetCommError(handle,CE_IOE);
return FALSE;
} else
result= TRUE;
@@ -833,7 +798,6 @@ BOOL WINAPI EscapeCommFunction(
if (result == -1)
{
result= FALSE;
- COMM_SetCommError(handle,CE_IOE);
}
else
result = TRUE;
@@ -912,8 +876,7 @@ BOOL WINAPI ClearCommError(
release_comm_fd( handle, fd );
- COMM_GetCommError(handle, errors);
- COMM_SetCommError(handle, 0);
+ if (errors) *errors = 0; /* FIXME */
return TRUE;
}
@@ -1028,7 +991,6 @@ BOOL WINAPI SetCommState(
if ((tcgetattr(fd,&port)) == -1) {
int save_error = errno;
- COMM_SetCommError(handle,CE_IOE);
release_comm_fd( handle, fd );
ERR("tcgetattr error '%s'\n", strerror(save_error));
return FALSE;
@@ -1134,7 +1096,7 @@ BOOL WINAPI SetCommState(
#endif
default:
#if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
- { struct serial_struct nuts;
+ if (0) { struct serial_struct nuts;
int arby;
ioctl(fd, TIOCGSERIAL, &nuts);
nuts.custom_divisor = nuts.baud_base / lpdcb->BaudRate;
@@ -1156,7 +1118,6 @@ BOOL WINAPI SetCommState(
#endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
- COMM_SetCommError(handle,IE_BAUDRATE);
release_comm_fd( handle, fd );
ERR("baudrate %ld\n",lpdcb->BaudRate);
return FALSE;
@@ -1243,7 +1204,6 @@ BOOL WINAPI SetCommState(
break;
#endif
default:
- COMM_SetCommError(handle,IE_BAUDRATE);
release_comm_fd( handle, fd );
ERR("baudrate %ld\n",lpdcb->BaudRate);
return FALSE;
@@ -1286,7 +1246,6 @@ BOOL WINAPI SetCommState(
stopbits = TWOSTOPBITS;
port.c_iflag &= ~INPCK;
} else {
- COMM_SetCommError(handle,IE_BYTESIZE);
release_comm_fd( handle, fd );
ERR("Cannot set MARK Parity\n");
return FALSE;
@@ -1297,7 +1256,6 @@ BOOL WINAPI SetCommState(
bytesize +=1;
port.c_iflag &= ~INPCK;
} else {
- COMM_SetCommError(handle,IE_BYTESIZE);
release_comm_fd( handle, fd );
ERR("Cannot set SPACE Parity\n");
return FALSE;
@@ -1305,7 +1263,6 @@ BOOL WINAPI SetCommState(
break;
#endif
default:
- COMM_SetCommError(handle,IE_BYTESIZE);
release_comm_fd( handle, fd );
ERR("Parity\n");
return FALSE;
@@ -1327,7 +1284,6 @@ BOOL WINAPI SetCommState(
port.c_cflag |= CS8;
break;
default:
- COMM_SetCommError(handle,IE_BYTESIZE);
release_comm_fd( handle, fd );
ERR("ByteSize\n");
return FALSE;
@@ -1342,7 +1298,6 @@ BOOL WINAPI SetCommState(
port.c_cflag |= CSTOPB;
break;
default:
- COMM_SetCommError(handle,IE_BYTESIZE);
release_comm_fd( handle, fd );
ERR("StopBits\n");
return FALSE;
@@ -1368,10 +1323,9 @@ BOOL WINAPI SetCommState(
if (tcsetattr(fd,TCSANOW,&port)==-1) { /* otherwise it hangs with pending input*/
ERR("tcsetattr error '%s'\n", strerror(errno));
- COMM_SetCommError(handle,CE_IOE);
ret = FALSE;
} else {
- COMM_SetCommError(handle,0);
+ ClearCommError(handle, NULL, NULL);
ret = TRUE;
}
@@ -1431,7 +1385,6 @@ BOOL WINAPI GetCommState(
if (tcgetattr(fd, &port) == -1) {
int save_error=errno;
ERR("tcgetattr error '%s'\n", strerror(save_error));
- COMM_SetCommError(handle,CE_IOE);
release_comm_fd( handle, fd );
return FALSE;
}
@@ -1620,8 +1573,6 @@ BOOL WINAPI GetCommState(
lpdcb->XonLim = 10;
lpdcb->XoffLim = 10;
- COMM_SetCommError(handle,0);
-
TRACE("OK\n");
TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
diff --git a/dlls/kernel/tests/comm.c b/dlls/kernel/tests/comm.c
index ed79b15..794ded2 100644
--- a/dlls/kernel/tests/comm.c
+++ b/dlls/kernel/tests/comm.c
@@ -804,6 +804,18 @@ static void test_ClearCommErrors(HANDLE
trace("test_ClearCommErrors done\n");
}
+static void test_non_pending_errors(HANDLE hcom)
+{
+ DCB dcb;
+ DWORD err;
+
+ ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
+ dcb.ByteSize = 255; /* likely bogus */
+ ok(!SetCommState(hcom, &dcb), "SetCommState should have failed\n");
+ ok(ClearCommError(hcom, &err, NULL), "ClearCommError should succeed\n");
+ ok(!(err & CE_MODE), "ClearCommError shouldn't set CE_MODE byte in this case (%lx)\n", err);
+}
+
/**/
static void test_LoopbackRead(HANDLE hcom)
{
@@ -1613,7 +1625,7 @@ static void test_WaitBreak(HANDLE hcom)
START_TEST(comm)
{
HANDLE hcom;
- /* use variabel and not #define to compile the code */
+ /* use variables and not #define to compile the code */
BOOL loopback_txd_rxd = LOOPBACK_TXD_RXD;
BOOL loopback_rts_cts = LOOPBACK_CTS_RTS;
BOOL loopback_dtr_dsr = LOOPBACK_DTR_DSR;
@@ -1632,10 +1644,16 @@ START_TEST(comm)
hcom = test_OpenComm(FALSE);
if (hcom != INVALID_HANDLE_VALUE)
{
- Sleep(200); /* Give the laster cahacter of test_waittxempty to drop into the receiver*/
+ Sleep(200); /* Give the laster character of test_waittxempty to drop into the receiver */
test_ClearCommErrors(hcom);
CloseHandle(hcom);
}
+ hcom = test_OpenComm(FALSE);
+ if (hcom != INVALID_HANDLE_VALUE)
+ {
+ test_non_pending_errors(hcom);
+ CloseHandle(hcom);
+ }
if((loopback_txd_rxd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
{
test_LoopbackRead(hcom);
diff --git a/server/protocol.def b/server/protocol.def
index 4b55734..c7ec5f9 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1673,7 +1673,6 @@ enum message_type
unsigned int writeconst;
unsigned int writemult;
unsigned int eventmask;
- unsigned int commerror;
@END
@@ -1687,11 +1686,9 @@ enum message_type
unsigned int writeconst;
unsigned int writemult;
unsigned int eventmask;
- unsigned int commerror;
@END
#define SERIALINFO_SET_TIMEOUTS 0x01
#define SERIALINFO_SET_MASK 0x02
-#define SERIALINFO_SET_ERROR 0x04
/* Create an async I/O */
diff --git a/server/serial.c b/server/serial.c
index 42d274f..f85f35d 100644
--- a/server/serial.c
+++ b/server/serial.c
@@ -82,7 +82,6 @@ struct serial
unsigned int writemult;
unsigned int eventmask;
- unsigned int commerror;
struct termios original;
@@ -146,7 +145,6 @@ struct object *create_serial( struct fd
serial->writemult = 0;
serial->writeconst = 0;
serial->eventmask = 0;
- serial->commerror = 0;
list_init( &serial->read_q );
list_init( &serial->write_q );
list_init( &serial->wait_q );
@@ -323,9 +321,6 @@ DECL_HANDLER(get_serial_info)
/* event mask */
reply->eventmask = serial->eventmask;
- /* comm port error status */
- reply->commerror = serial->commerror;
-
release_object( serial );
}
}
@@ -356,12 +351,6 @@ DECL_HANDLER(set_serial_info)
}
}
- /* comm port error status */
- if (req->flags & SERIALINFO_SET_ERROR)
- {
- serial->commerror = req->commerror;
- }
-
release_object( serial );
}
}
More information about the wine-patches
mailing list