3-5 c6
This commit is contained in:
parent
d8a231f2ea
commit
b6545a7e39
|
@ -325,6 +325,15 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
|
|||
}
|
||||
|
||||
if (fileio_is_io_available(pio, TRUE) == FALSE) {
|
||||
/* Workaround for - ReadFileEx is restting file pointer to beginning upon encoutering a EOF*/
|
||||
/* If there was a previous read and if the file pointer is at 0, then its been reset*/
|
||||
if ((pio->type == FILE_FD) && (pio->read_details.completed > 0)){
|
||||
DWORD fp = SetFilePointer(pio->handle, 0, NULL, FILE_CURRENT);
|
||||
if (fp == 0) {
|
||||
errno = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (-1 == fileio_ReadFileEx(pio)) {
|
||||
if ((pio->type == PIPE_FD) && (errno == ERROR_NEGATIVE_SEEK)) {
|
||||
/* write end of the pipe closed */
|
||||
|
@ -355,7 +364,8 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
|
|||
if (pio->read_details.error) {
|
||||
errno = errno_from_Win32Error(pio->read_details.error);
|
||||
/*write end of the pipe is closed or pipe broken or eof reached*/
|
||||
if ((errno == ERROR_BROKEN_PIPE) || (errno == ERROR_HANDLE_EOF)) {
|
||||
if ((pio->read_details.error == ERROR_BROKEN_PIPE) ||
|
||||
(pio->read_details.error == ERROR_HANDLE_EOF)) {
|
||||
debug2("no more data");
|
||||
errno = 0;
|
||||
pio->read_details.error = 0;
|
||||
|
|
|
@ -603,10 +603,7 @@ socketio_close(struct w32_io* pio) {
|
|||
struct acceptEx_context *ctx = (struct acceptEx_context*)pio->internal.context;
|
||||
if (ctx->accept_socket != INVALID_SOCKET)
|
||||
closesocket(ctx->accept_socket);
|
||||
if (ctx->lpOutputBuf)
|
||||
free(ctx->lpOutputBuf);
|
||||
/* TODO: check why this is crashing */
|
||||
//free(pio->internal.context);
|
||||
free(pio->internal.context);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,6 +64,40 @@ file_blocking_io_tests()
|
|||
TEST_DONE();
|
||||
}
|
||||
|
||||
void file_simple_fileio()
|
||||
{
|
||||
char* small_write_buf = "sample payload";
|
||||
char small_read_buf[SMALL_RECV_BUF_SIZE];
|
||||
|
||||
int f;
|
||||
TEST_START("file io");
|
||||
f = open("e:\\tmp.txt", O_WRONLY | O_CREAT | O_TRUNC);
|
||||
ASSERT_INT_NE(f, -1);
|
||||
close(f);
|
||||
f = open("e:\\tmp.txt", O_RDONLY);
|
||||
ASSERT_INT_NE(f, -1);
|
||||
ret = read(f, small_read_buf, SMALL_RECV_BUF_SIZE);
|
||||
ASSERT_INT_EQ(ret, 0);
|
||||
close(f);
|
||||
f = open("e:\\tmp.txt", O_WRONLY | O_CREAT | O_TRUNC);
|
||||
ASSERT_INT_NE(f, -1);
|
||||
ret = write(f, small_write_buf, strlen(small_write_buf));
|
||||
ASSERT_INT_EQ(ret, strlen(small_write_buf));
|
||||
close(f);
|
||||
f = open("e:\\tmp.txt", O_RDONLY);
|
||||
ASSERT_INT_NE(f, -1);
|
||||
ret = read(f, small_read_buf, SMALL_RECV_BUF_SIZE);
|
||||
ASSERT_INT_EQ(ret, strlen(small_write_buf));
|
||||
small_read_buf[ret] = '\0';
|
||||
ASSERT_STRING_EQ(small_write_buf, small_read_buf);
|
||||
ret = read(f, small_read_buf, SMALL_RECV_BUF_SIZE);
|
||||
ASSERT_INT_EQ(ret, 0);
|
||||
close(f);
|
||||
TEST_DONE();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
file_nonblocking_io_tests()
|
||||
{
|
||||
|
@ -188,6 +222,7 @@ void
|
|||
file_tests()
|
||||
{
|
||||
w32posix_initialize();
|
||||
//file_simple_fileio();
|
||||
file_blocking_io_tests();
|
||||
file_nonblocking_io_tests();
|
||||
file_select_tests();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys\stat.h>
|
||||
#include <io.h>
|
||||
#include "test_helper.h"
|
||||
|
||||
|
@ -17,9 +18,9 @@ void tests(void)
|
|||
{
|
||||
_set_abort_behavior(0, 1);
|
||||
log_init(NULL, 7, 2, 0);
|
||||
logfd = _open("unittests.log", O_WRONLY | O_CREAT );
|
||||
logfd = _open("unittests.log", _O_WRONLY | _O_CREAT | _O_TRUNC, S_IREAD | S_IWRITE | _O_NOINHERIT);
|
||||
socket_tests();
|
||||
file_tests();
|
||||
_close(logfd);
|
||||
if (logfd > 0) _close(logfd);
|
||||
return;
|
||||
}
|
Loading…
Reference in New Issue