From fe018e9e16858cd9e1505de2a460c06f02043870 Mon Sep 17 00:00:00 2001 From: "Wesley W. Terpstra" <w.terpstra@gsi.de> Date: Thu, 23 Feb 2012 13:23:38 +0000 Subject: [PATCH] TCP connection established ok. --- api/format/slave.c | 8 ++++++++ api/transport/posix-ip.c | 12 +++++++++--- api/transport/posix-ip.h | 5 ++--- api/transport/posix-tcp.c | 7 +------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/api/format/slave.c b/api/format/slave.c index bd4685b..16ed004 100644 --- a/api/format/slave.c +++ b/api/format/slave.c @@ -125,12 +125,20 @@ void eb_device_slave(eb_socket_t socketp, eb_transport_t transportp, eb_device_t /* < 8: protocol violation! */ if (active) goto kill; /* active link not probed! */ + widths = buffer[3]; + widths = eb_width_refine(widths & socket->widths); + buffer[2] = 0x12; /* V1 probe response */ buffer[3] = socket->widths; /* passive and transport both use socket widths */ + if (passive) device->widths = widths; /* This will be the negotiated width */ + /* Bytes 4-7 are echoed back */ eb_transports[transport->link_type].send(transport, link, buffer, 8); + /* Kill the link if negotiation is impossible */ + if (!eb_width_possible(widths)) goto kill; + return; } diff --git a/api/transport/posix-ip.c b/api/transport/posix-ip.c index 84e6f19..e447eb1 100644 --- a/api/transport/posix-ip.c +++ b/api/transport/posix-ip.c @@ -123,12 +123,18 @@ socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int type, return len; } -void eb_posix_ip_non_blocking(eb_posix_sock_t sock, unsigned long on) { +void eb_posix_ip_force_non_blocking(eb_posix_sock_t sock, unsigned long on) { #if defined(__WIN32) ioctlsocket(sock, FIONBIO, &on); -#elif defined(EB_POSIX_IP_NON_BLOCKING_NOOP) - /* no-op. DONTWAIT is faster */ #else ioctl(sock, FIONBIO, &on); #endif } + +void eb_posix_ip_non_blocking(eb_posix_sock_t sock, unsigned long on) { +#if defined(EB_POSIX_IP_NON_BLOCKING_NOOP) + /* no-op. DONTWAIT is faster */ +#else + eb_posix_ip_force_non_blocking(sock, on); +#endif +} diff --git a/api/transport/posix-ip.h b/api/transport/posix-ip.h index b70c2f1..1cea78c 100644 --- a/api/transport/posix-ip.h +++ b/api/transport/posix-ip.h @@ -51,17 +51,16 @@ typedef SOCKET eb_posix_sock_t; typedef eb_descriptor_t eb_posix_sock_t; -#if defined(MSG_DONTWAIT) && defined(SOCK_NONBLOCK) +#if defined(MSG_DONTWAIT) #define EB_POSIX_IP_NON_BLOCKING_NOOP #else -#ifndef MSG_DONTWAIT #define MSG_DONTWAIT 0 #endif -#endif EB_PRIVATE void eb_posix_ip_close(eb_posix_sock_t sock); EB_PRIVATE eb_posix_sock_t eb_posix_ip_open(int type, const char* port); EB_PRIVATE socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int type, struct sockaddr_storage* out); EB_PRIVATE void eb_posix_ip_non_blocking(eb_posix_sock_t sock, unsigned long on); +EB_PRIVATE void eb_posix_ip_force_non_blocking(eb_posix_sock_t sock, unsigned long on); #endif diff --git a/api/transport/posix-tcp.c b/api/transport/posix-tcp.c index 8eebfd7..5bf2268 100644 --- a/api/transport/posix-tcp.c +++ b/api/transport/posix-tcp.c @@ -46,7 +46,7 @@ eb_status_t eb_posix_tcp_open(struct eb_transport* transportp, const char* port) return EB_ADDRESS; } - eb_posix_ip_non_blocking(sock, 1); + eb_posix_ip_force_non_blocking(sock, 1); transport = (struct eb_posix_tcp_transport*)transportp; transport->port = sock; @@ -160,12 +160,7 @@ int eb_posix_tcp_accept(struct eb_transport* transportp, struct eb_link* result_ transport = (struct eb_posix_tcp_transport*)transportp; -#ifdef EB_POSIX_IP_NON_BLOCKING_NOOP - sock = accept4(transport->port, 0, 0, SOCK_NONBLOCK); -#else sock = accept(transport->port, 0, 0); -#endif - if (sock == -1) { if (errno != EAGAIN) return -1; return 0; -- GitLab