]> git.tdb.fi Git - libs/core.git/commitdiff
Use separate members for Pipe read/write handles
authorMikko Rasa <tdb@tdb.fi>
Wed, 30 May 2012 17:41:03 +0000 (17:41 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 30 May 2012 17:41:03 +0000 (17:41 +0000)
source/io/pipe.cpp
source/io/pipe.h

index d1bc5c4177deb590e539bbf2f96087f15b64c770..12f8fbd3886ea7f269b125691a19b2074ee16d11 100644 (file)
@@ -14,16 +14,16 @@ namespace Msp {
 namespace IO {
 
 Pipe::Pipe():
-       reader(handle[0], 1024)
+       reader(read_handle, 1024)
 {
 #ifdef WIN32
        string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
-       *handle[0] = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
-       if(!handle[0])
+       *read_handle = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
+       if(!read_handle)
                throw system_error("CreateNamedPipe");
 
-       *handle[1] = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
-       if(!handle[1])
+       *write_handle = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
+       if(!write_handle)
        {
                unsigned err = GetLastError();
                CloseHandle(*handle[0]);
@@ -34,8 +34,8 @@ Pipe::Pipe():
        if(pipe(pipe_fd)==-1)
                throw system_error("pipe");
 
-       *handle[0] = pipe_fd[0];
-       *handle[1] = pipe_fd[1];
+       *read_handle = pipe_fd[0];
+       *write_handle = pipe_fd[1];
 #endif
 
        set_events(P_INPUT);
@@ -46,8 +46,8 @@ Pipe::~Pipe()
        set_events(P_NONE);
 
        signal_flush_required.emit();
-       sys_close(handle[0]);
-       sys_close(handle[1]);
+       sys_close(read_handle);
+       sys_close(write_handle);
 }
 
 void Pipe::set_block(bool b)
@@ -57,10 +57,10 @@ void Pipe::set_block(bool b)
                mode = (mode|M_NONBLOCK);
 
 #ifndef WIN32
-       int flags = fcntl(*handle[0], F_GETFD);
-       fcntl(*handle[0], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
-       flags = fcntl(*handle[1], F_GETFD);
-       fcntl(*handle[1], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
+       int flags = fcntl(*read_handle, F_GETFD);
+       fcntl(*read_handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
+       flags = fcntl(*write_handle, F_GETFD);
+       fcntl(*write_handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
 #endif
 }
 
@@ -69,7 +69,7 @@ unsigned Pipe::do_write(const char *buf, unsigned size)
        if(size==0)
                return 0;
 
-       return sys_write(handle[1], buf, size);
+       return sys_write(write_handle, buf, size);
 }
 
 unsigned Pipe::do_read(char *buf, unsigned size)
index 73731776856a2fc1c9d90530935fc4009ffaf2cc..6d65a9a6b2f6bc140014c281b0f7b0c01e9f4b94 100644 (file)
@@ -11,7 +11,8 @@ namespace IO {
 class Pipe: public EventObject
 {
 private:
-       Handle handle[2];
+       Handle read_handle;
+       Handle write_handle;
        EventReader reader;
 
 public: