Thanks for the quick reply!

On Friday, December 6, 2013 2:49:15 AM UTC-6, Saúl Ibarra Corretgé wrote:
>
>
> What version of libuv did you test? I don't see how you could get 
> EINPROGRESS in your callback, on Unix, you can only get EBADF or 0, 
> AFAIS: https://github.com/joyent/libuv/blob/master/src/unix/poll.c#L30-L50 
>

The version I'm building against for node.js 0.10.12 is libuv 0.10.11. I 
should probably mention that when I said I was getting
EINPROGRESS back, I was being inaccurate - I was getting -1 back as the 
status, and the errno was EINPROGRESS. I've since tried building
against libuv 0.10.12, and I do indeed get EBADF back in the status instead 
of just -1.
 

>
> Does the libuv test suite pass for you? It contains a few uv_poll_t test 
> cases. 
>
>
It does (well, except for the TCP/IP v6 cases, but that's not a big deal). 
I should mention that I'm running all this on a Raspberry Pi
running the latest version of Raspbian. I'm building against BlueZ version 
5.7 as well.

Last, do you have a small test case which reproduces this? 
>
>
I do. You'll need BlueZ headers and libraries installed to make it build. 
I've attached the C++ test file.

Here's how I'm building it:

$ c++ -g -fpermissive -I/home/pi/.node-gyp/0.10.12/deps/uv/include/ 
-lbluetooth -lpthread -lrt -o test test.cc ../libuv/out/Debug/libuv.a

I went ahead and built it on my pi against libuv 0.10.12,
which gave me the following output when I ran it:

$ ./test
connect returned -1, errno = 115
onConnect called, status = -9

Thanks for your help!

-Jack

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/groups/opt_out.
#include <errno.h>
#include <unistd.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
#include <uv.h>

void onConnect(uv_poll_t* handle, int status, int events) {
  printf("onConnect called, status = %d\n", status);
}

int main(int argc, const char** argv) {
  uv_loop_t *loop = uv_default_loop();

  int sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
  if (sock < 0)
  {
    perror("socket");
    return -1;
  }

	struct sockaddr_l2 addr;

	memset(&addr, 0, sizeof(addr));
	addr.l2_family = AF_BLUETOOTH;
	bacpy(&addr.l2_bdaddr, BDADDR_ANY);
  addr.l2_cid = htobs(4);
	addr.l2_bdaddr_type = BDADDR_LE_PUBLIC;

	if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
		int error = -errno;
		return error;
	}

  struct l2cap_options l2o;
  socklen_t len;

  memset(&l2o, 0, sizeof(l2o));
  len = sizeof(l2o);
  if (getsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, &len) < 0) {
    perror("getsockopt");
    return -1;
  }

  l2o.mode = L2CAP_MODE_BASIC;

  if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) {
    perror("setsockopt");
    return -1;
  }

	int r = fcntl(sock, F_GETFL);
	if (r < 0) {
    perror("fcntl");
		close(sock);
    return -1;
	}

	if (fcntl(sock, F_SETFL, r | O_NONBLOCK) < 0) {
    perror("fcntl");
		close(sock);
    return -1;
	}

	int err;
	memset(&addr, 0, sizeof(addr));
	addr.l2_family = AF_BLUETOOTH;
	str2ba("BC:6A:29:C3:52:A9", &addr.l2_bdaddr);
  addr.l2_cid = htobs(4);
	addr.l2_bdaddr_type = BDADDR_LE_PUBLIC;

	err = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
  printf("connect returned %d, errno = %d\n", err, errno);
	if (err < 0 && !(errno == EAGAIN || errno == EINPROGRESS))
  {
    perror("connect");
    return -1;
  }
  uv_poll_t* poll_handle = new uv_poll_t;
  uv_poll_init_socket(uv_default_loop(), poll_handle, sock);
  uv_poll_start(poll_handle, UV_WRITABLE, onConnect);

  uv_run(loop, UV_RUN_DEFAULT);
}

Reply via email to