mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-19 20:15:01 +02:00
3-3 C1
This commit is contained in:
parent
1a66801a45
commit
bc122a7472
@ -35,6 +35,12 @@ void file_blocking_io_tests()
|
||||
TEST_START("pipe read and write");
|
||||
r = pipeio[0];
|
||||
w = pipeio[1];
|
||||
ret = write(r, small_send_buf, strlen(small_send_buf));
|
||||
ASSERT_INT_EQ(ret, -1);
|
||||
ASSERT_INT_EQ(errno, EBADF);
|
||||
ret = read(w, small_recv_buf, SMALL_RECV_BUF_SIZE);
|
||||
ASSERT_INT_EQ(ret, -1);
|
||||
ASSERT_INT_EQ(errno, EBADF);
|
||||
ret = write(w, small_send_buf, strlen(small_send_buf));
|
||||
ASSERT_INT_EQ(ret, strlen(small_send_buf));
|
||||
ret = read(r, small_recv_buf, SMALL_RECV_BUF_SIZE);
|
||||
|
@ -91,7 +91,9 @@ int fileio_pipe(struct w32_io* pio[2]) {
|
||||
memset(pio_write, 0, sizeof(struct w32_io));
|
||||
|
||||
pio_read->handle = read_handle;
|
||||
pio_read->internal.state = PIPE_READ_END;
|
||||
pio_write->handle = write_handle;
|
||||
pio_write->internal.state = PIPE_WRITE_END;
|
||||
|
||||
pio[0] = pio_read;
|
||||
pio[1] = pio_write;
|
||||
@ -269,6 +271,11 @@ int fileio_ReadFileEx(struct w32_io* pio) {
|
||||
int fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
|
||||
int bytes_copied;
|
||||
|
||||
if ((pio->type == PIPE_FD) && (pio->internal.state == PIPE_WRITE_END)) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//if read is pending
|
||||
if (pio->read_details.pending) {
|
||||
errno = EAGAIN;
|
||||
@ -343,6 +350,11 @@ VOID CALLBACK WriteCompletionRoutine(
|
||||
int fileio_write(struct w32_io* pio, const void *buf, unsigned int max) {
|
||||
int bytes_copied;
|
||||
|
||||
if ((pio->type == PIPE_FD) && (pio->internal.state == PIPE_READ_END)) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pio->write_details.pending) {
|
||||
if (w32_io_is_blocking(pio))
|
||||
{
|
||||
@ -431,7 +443,7 @@ int fileio_fstat(struct w32_io* pio, struct stat *buf) {
|
||||
|
||||
|
||||
int fileio_isatty(struct w32_io* pio) {
|
||||
return (pio->type == CONSOLE_FD) ? TRUE : FALSE;
|
||||
return (GetFileType(pio->handle) == FILE_TYPE_CHAR) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -481,6 +493,7 @@ int fileio_on_select(struct w32_io* pio, BOOL rd) {
|
||||
if (!pio->read_details.pending && !fileio_is_io_available(pio, rd))
|
||||
return fileio_ReadFileEx(pio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -489,7 +502,8 @@ int fileio_close(struct w32_io* pio) {
|
||||
CancelIo(pio->handle);
|
||||
//let queued APCs (if any) drain
|
||||
SleepEx(0, TRUE);
|
||||
CloseHandle(pio->handle);
|
||||
if (pio->type != STD_IO_FD) //STD handles are never explicitly closed
|
||||
CloseHandle(pio->handle);
|
||||
|
||||
if (pio->read_details.buf)
|
||||
free(pio->read_details.buf);
|
||||
|
@ -229,7 +229,6 @@ int w32_recv(int fd, void *buf, size_t len, int flags) {
|
||||
int w32_send(int fd, const void *buf, size_t len, int flags) {
|
||||
debug3("fd:%d", fd);
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_send(fd_table.w32_ios[fd], buf, len, flags);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,11 @@ enum w32_io_sock_state {
|
||||
SOCK_CONNECTED = 4
|
||||
};
|
||||
|
||||
enum w32_io_pipe_state {
|
||||
PIPE_READ_END = 1,
|
||||
PIPE_WRITE_END = 2
|
||||
};
|
||||
|
||||
struct w32_io {
|
||||
OVERLAPPED read_overlapped;
|
||||
OVERLAPPED write_overlapped;
|
||||
|
Loading…
x
Reference in New Issue
Block a user