Sha256: 9ea791036d6a14ba1e592ec54f3e135759c29d77c1c5d554328f3a65fd84013c

Contents?: true

Size: 1.9 KB

Versions: 51

Compression:

Stored size: 1.9 KB

Contents

/*
 * Copyright (c) 2007 Wayne Meissner. All rights reserved.
 *
 * For licensing, see LICENSE.SPECS
 */

#ifdef _WIN32
#include <windows.h>
#include "PipeHelper.h"

int pipeHelperCreatePipe(FD_TYPE pipefd[2])
{
    char name[ MAX_PATH ];
    static int pipe_idx = 0;
    sprintf( name, "\\\\.\\Pipe\\pipeHelper-%u-%i",
             (unsigned int)GetCurrentProcessId(), pipe_idx++ );

    pipefd[0] = CreateNamedPipe( name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
                         PIPE_TYPE_BYTE | PIPE_WAIT,
                         1,             // Number of pipes
                         5,         // Out buffer size
                         5,         // In buffer size
                         60 * 1000,    // Timeout in ms
                         NULL );
    if(pipefd[0] == INVALID_HANDLE_VALUE)
        return -1;

    pipefd[1] = CreateFile( name, GENERIC_WRITE, 0, NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);

    if(pipefd[1] == INVALID_HANDLE_VALUE) {
        CloseHandle( pipefd[0] );
        return -1;
    }
    return 0;
}

char pipeHelperReadChar(FD_TYPE fd, int timeout)
{
    char d;
    OVERLAPPED ovl;
    ZeroMemory(&ovl, sizeof(ovl));
    ovl.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if( ReadFile(fd, &d, 1, NULL, &ovl) == 0) {
        DWORD recvd = 0;;
        DWORD res = WaitForSingleObject(ovl.hEvent, timeout * 1000);
        if( res != WAIT_OBJECT_0 ) {
            CloseHandle(ovl.hEvent);
            return 0;
        }
        if( GetOverlappedResult(fd, &ovl, &recvd, FALSE) == 0 ) {
            CloseHandle(ovl.hEvent);
            return 0;
        }
    }
    CloseHandle(ovl.hEvent);
    return d;
}

int pipeHelperWriteChar(FD_TYPE fd, char c)
{
    DWORD written;
    return WriteFile(fd, &c, 1, &written, NULL) == 0 ? 0 : 1;
}

void pipeHelperClosePipe(FD_TYPE fd) {
    CloseHandle(fd);
}

#endif

Version data entries

51 entries across 49 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
ffi-1.9.21-x86-mingw32 spec/ffi/fixtures/PipeHelperWindows.c
ffi-1.9.21-x64-mingw32 spec/ffi/fixtures/PipeHelperWindows.c
ffi-1.9.21 spec/ffi/fixtures/PipeHelperWindows.c
tdiary-5.0.7 vendor/bundle/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
tdiary-5.0.6 vendor/bundle/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
tdiary-5.0.5 vendor/bundle/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/ffi-1.9.18/spec/ffi/fixtures/PipeHelperWindows.c