From MSDN OVERLAPPED: "Functions such as WriteFile set the event to the
nonsignaled state before they begin an I/O operation"
So the ResetEvent additions are meaningless... Why did you add them?
Gunnar
ekohl(a)svn.reactos.com wrote:
Fix calls to ReadFile and WriteFile for asynchronous
I/O.
Modified: trunk/reactos/lib/rpcrt4/rpc_message.c
------------------------------------------------------------------------
*Modified: trunk/reactos/lib/rpcrt4/rpc_message.c*
--- trunk/reactos/lib/rpcrt4/rpc_message.c 2005-03-05 11:27:15 UTC (rev 13824)
+++ trunk/reactos/lib/rpcrt4/rpc_message.c 2005-03-05 11:38:48 UTC (rev 13825)
@@ -265,10 +265,15 @@
}
/* transmit packet header */
- if (!WriteFile(Connection->conn, Header, hdr_size, &count, NULL)) {
+ ResetEvent(Connection->ovl.hEvent);
+ if (!WriteFile(Connection->conn, Header, hdr_size, &count,
&Connection->ovl)) {
WARN("WriteFile failed with error %ld\n", GetLastError());
return GetLastError();
}
+ if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &count,
TRUE)) {
+ WARN("GetOverlappedResult failed with error %ld\n", GetLastError());
+ return GetLastError();
+ }
/* fragment consisted of header only and is the last one */
if (hdr_size == Header->common.frag_len &&
@@ -277,10 +282,15 @@
}
/* send the fragment data */
- if (!WriteFile(Connection->conn, buffer_pos, Header->common.frag_len -
hdr_size, &count, NULL)) {
+ ResetEvent(Connection->ovl.hEvent);
+ if (!WriteFile(Connection->conn, buffer_pos, Header->common.frag_len -
hdr_size, &count, &Connection->ovl)) {
WARN("WriteFile failed with error %ld\n", GetLastError());
return GetLastError();
}
+ if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &count,
TRUE)) {
+ WARN("GetOverlappedResult failed with error %ld\n", GetLastError());
+ return GetLastError();
+ }
Header->common.flags &= ~RPC_FLG_FIRST;
}
@@ -309,9 +319,15 @@
TRACE("(%p, %p, %p)\n", Connection, Header, pMsg);
/* read packet common header */
- if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead,
NULL)) {
+ ResetEvent(Connection->ovl.hEvent);
+ if (!ReadFile(Connection->conn, &common_hdr, sizeof(common_hdr), &dwRead,
&Connection->ovl)) {
+ WARN("ReadFile failed with error %ld\n", GetLastError());
+ status = RPC_S_PROTOCOL_ERROR;
+ goto fail;
+ }
+ if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &dwRead,
TRUE)) {
if (GetLastError() != ERROR_MORE_DATA) {
- WARN("ReadFile failed with error %ld\n", GetLastError());
+ WARN("GetOverlappedResult failed with error %ld\n", GetLastError());
status = RPC_S_PROTOCOL_ERROR;
goto fail;
}
@@ -339,10 +355,16 @@
memcpy(*Header, &common_hdr, sizeof(common_hdr));
/* read the rest of packet header */
+ ResetEvent(Connection->ovl.hEvent);
if (!ReadFile(Connection->conn, &(*Header)->common + 1,
- hdr_length - sizeof(common_hdr), &dwRead, NULL)) {
+ hdr_length - sizeof(common_hdr), &dwRead, &Connection->ovl))
{
+ WARN("ReadFile failed with error %ld\n", GetLastError());
+ status = RPC_S_PROTOCOL_ERROR;
+ goto fail;
+ }
+ if (!GetOverlappedResult(Connection->conn, &Connection->ovl, &dwRead,
TRUE)) {
if (GetLastError() != ERROR_MORE_DATA) {
- WARN("ReadFile failed with error %ld\n", GetLastError());
+ WARN("GetOverlappedResult failed with error %ld\n", GetLastError());
status = RPC_S_PROTOCOL_ERROR;
goto fail;
}
@@ -352,6 +374,7 @@
goto fail;
}
+
/* read packet body */
switch (common_hdr.ptype) {
case PKT_RESPONSE:
@@ -379,13 +402,20 @@
goto fail;
}
- if (data_length == 0) dwRead = 0; else
- if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead, NULL)) {
- if (GetLastError() != ERROR_MORE_DATA) {
+ if (data_length == 0) dwRead = 0; else {
+ ResetEvent(Connection->ovl.hEvent);
+ if (!ReadFile(Connection->conn, buffer_ptr, data_length, &dwRead,
&Connection->ovl)) {
WARN("ReadFile failed with error %ld\n", GetLastError());
status = RPC_S_PROTOCOL_ERROR;
goto fail;
}
+ if (!GetOverlappedResult(Connection->conn, &Connection->ovl,
&dwRead, TRUE)) {
+ if (GetLastError() != ERROR_MORE_DATA) {
+ WARN("GetOverlappedResult failed with error %ld\n",
GetLastError());
+ status = RPC_S_PROTOCOL_ERROR;
+ goto fail;
+ }
+ }
}
if (dwRead != data_length) {
status = RPC_S_PROTOCOL_ERROR;
@@ -403,10 +433,16 @@
TRACE("next header\n");
/* read the header of next packet */
- if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead, NULL)) {
+ ResetEvent(Connection->ovl.hEvent);
+ if (!ReadFile(Connection->conn, *Header, hdr_length, &dwRead,
&Connection->ovl)) {
+ WARN("ReadFile failed with error %ld\n", GetLastError());
+ status = GetLastError();
+ goto fail;
+ }
+ if (!GetOverlappedResult(Connection->conn, &Connection->ovl,
&dwRead, TRUE)) {
if (GetLastError() != ERROR_MORE_DATA) {
- WARN("ReadFile failed with error %ld\n", GetLastError());
- status = GetLastError();
+ WARN("GetOverlappedResult failed with error %ld\n",
GetLastError());
+ status = RPC_S_PROTOCOL_ERROR;
goto fail;
}
}
------------------------------------------------------------------------
_______________________________________________
Ros-diffs mailing list
Ros-diffs(a)reactos.com
http://reactos.com:8080/mailman/listinfo/ros-diffs