Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

pipe_echo_server example fails on Windows #60

Open
ghost opened this issue Jul 27, 2015 · 5 comments
Open

pipe_echo_server example fails on Windows #60

ghost opened this issue Jul 27, 2015 · 5 comments

Comments

@ghost
Copy link

ghost commented Jul 27, 2015

I'm getting "Bind error EACCESS" error on the uv_pipe_bind on Windows. IOJS & Node versions 2.3.1, 64-bit Windows 8.1 running under Git Bash.

uv_loop_t *loop;
uv_process_t child_req;
uv_process_options_t options;

bool MyPackage::OpenPipe()
{

loop = uv_default_loop();
uv_pipe_t server;
uv_pipe_init(loop, &server, 0);

signal(SIGINT, remove_sock);

int q;
if ((q = uv_pipe_bind(&server, "echo.sock"))) {
fprintf(stderr, "Bind error %s\n", uv_err_name(q)); // <-- Errors here
return false;
}

... etc ...

It looks like you are using "CreateNamedPipeW" (http://manned.org/CreateNamedPipeW/c4d0b097) under Windows. Is that valid, or do you mean to use "CreatedNamedPipe" (https://msdn.microsoft.com/en-us/library/windows/desktop/aa365150(v=vs.85).aspx) instead?

@douxing
Copy link

douxing commented Aug 4, 2015

i have met this problem before, you should not use "echo.sock" as the second param in uv_pipe_bind function, instead, according to microsoft, try using a name like "\\.\pipe\":

uv_pipe_bind(&server, "\\\\.\\pipe\\myepipe")

@nikhilm
Copy link
Owner

nikhilm commented Aug 4, 2015

Thanks for helping @douxing!

@ghost
Copy link
Author

ghost commented Aug 6, 2015

Thank you @douxing - that was the issue.

How do I convert the uv_buf_t to something useful, like a string for example?

In the echo_read for the pipe_echo_server example, I am trying to simply print out the buffer received, but half of the buffer always seems to get mangled.

Here is what I'm trying to do:

void echo_read(uv_stream_t client, ssize_t nread, const uv_buf_t *buf) {
if (nread < 0) {
if (nread != UV_EOF)
fprintf(stderr, "Read error %s\n", uv_err_name(nread));
uv_close((uv_handle_t
) client, NULL);
return;
}

fprintf(stdout, "%s\n", buf->base); // <--- this prints out 1/2 OK, and 1/2 mangled
free(buf->base);

}

@saghul
Copy link

saghul commented Aug 6, 2015

Use this form:

fprintf(stdout, "%.*s\n", nread, buf->base); 

Since the buffer might not be null terminated.

@douxing
Copy link

douxing commented Aug 7, 2015

@saghul I used to add an extra '\0' to buf->base to solve this, thank you for the "%.*s" format!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants