Пример #1
0
JL_DLLEXPORT int jl_ispty(uv_pipe_t *pipe)
{
    if (pipe->type != UV_NAMED_PIPE) return 0;
    size_t len = 0;
    if (uv_pipe_getsockname(pipe, NULL, &len) != UV_ENOBUFS) return 0;
    char *name = (char *) alloca(len);
    if (uv_pipe_getsockname(pipe, name, &len)) return 0;
    // return true if name matches regex:
    // ^\\\\?\\pipe\\(msys|cygwin)-[0-9a-z]{16}-[pt]ty[1-9][0-9]*-
    //jl_printf(JL_STDERR,"pipe_name: %s\n", name);
    int n = 0;
    if (!strncmp(name,"\\\\?\\pipe\\msys-",14))
        n = 14;
    else if (!strncmp(name,"\\\\?\\pipe\\cygwin-",16))
        n = 16;
    else
        return 0;
    //jl_printf(JL_STDERR,"prefix pass\n");
    name += n;
    for (int n = 0; n < 16; n++)
        if (!ishexchar(*name++)) return 0;
    //jl_printf(JL_STDERR,"hex pass\n");
    if ((*name++)!='-') return 0;
    if (*name != 'p' && *name != 't') return 0;
    name++;
    if (*name++ != 't' || *name++ != 'y') return 0;
    //jl_printf(JL_STDERR,"tty pass\n");
    return 1;
}
Пример #2
0
Файл: pipe.c Проект: imclab/pyuv
static PyObject *
Pipe_func_getsockname(Pipe *self)
{
#ifdef _WIN32
    /* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
    char buf[MAX_PATH * 4];
#else
    char buf[PATH_MAX];
#endif
    size_t buf_len;
    int err;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    buf_len = sizeof(buf);
    err = uv_pipe_getsockname(&self->pipe_h, buf, &buf_len);
    if (err < 0) {
        RAISE_UV_EXCEPTION(err, PyExc_PipeError);
        return NULL;
    }

    if (buf_len == 0) {
        return PyBytes_FromString("");
    } else if (buf[0] == '\0') {
        /* Linux abstract namespace */
        return PyBytes_FromStringAndSize(buf, buf_len);
    } else {
        return PyBytes_FromStringAndSize(buf, buf_len-1);
    }

}
Пример #3
0
static void pipe_client_connect_cb(uv_connect_t* req, int status) {
  char buf[1024];
  size_t len;
  int r;

  ASSERT(req == &connect_req);
  ASSERT(status == 0);

  len = sizeof buf;
  r = uv_pipe_getpeername(&pipe_client, buf, &len);
  ASSERT(r == 0);

  ASSERT(buf[len - 1] != 0);
  ASSERT(memcmp(buf, TEST_PIPENAME, len) == 0);

  len = sizeof buf;
  r = uv_pipe_getsockname(&pipe_client, buf, &len);
  ASSERT(r == 0 && len == 0);

  pipe_client_connect_cb_called++;


  uv_close((uv_handle_t*) &pipe_client, pipe_close_cb);
  uv_close((uv_handle_t*) &pipe_server, pipe_close_cb);
}
Пример #4
0
    bool getsockname(std::string& name)
    {
        std::vector<char> buf(100);
        size_t buf_size = buf.size();
        int r = uv_pipe_getsockname(get(), buf.data(), &buf_size);
        if (r == UV_ENOBUFS) {
            buf.resize(buf_size);
            r = uv_pipe_getsockname(get(), buf.data(), &buf_size);
        }

        if (r == 0)
        {
            name = std::string(buf.data(), buf_size);
            return true;
        }
        return false;
    }