From: David Antler Date: Mon, 6 Jun 2016 18:04:17 +0000 (-0700) Subject: Merge branch 'master' into windows-port X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8031c99214e4213a202edef846de68ad5f080fa0;p=contrib%2Fiotivity.git Merge branch 'master' into windows-port Change-Id: I87c2e5ee2d6c9574c2a50d83256d6845a340fd86 Signed-off-by: David Antler --- 8031c99214e4213a202edef846de68ad5f080fa0 diff --cc resource/csdk/connectivity/api/cacommon.h index 205327a,e725c44..1be743b --- a/resource/csdk/connectivity/api/cacommon.h +++ b/resource/csdk/connectivity/api/cacommon.h @@@ -486,33 -497,28 +508,35 @@@ typedef struc bool client; /**< client mode */ bool server; /**< server mode */ + CAPorts_t ports; + struct sockets { - void *threadpool; /**< threadpool between Initialize and Start */ - CASocket_t u6; /**< unicast IPv6 */ - CASocket_t u6s; /**< unicast IPv6 secure */ - CASocket_t u4; /**< unicast IPv4 */ - CASocket_t u4s; /**< unicast IPv4 secure */ - CASocket_t m6; /**< multicast IPv6 */ - CASocket_t m6s; /**< multicast IPv6 secure */ - CASocket_t m4; /**< multicast IPv4 */ - CASocket_t m4s; /**< multicast IPv4 secure */ - int netlinkFd; /**< netlink */ - int shutdownFds[2]; /**< shutdown pipe */ - int selectTimeout; /**< in seconds */ - int maxfd; /**< highest fd (for select) */ - bool started; /**< the IP adapter has started */ - bool terminate; /**< the IP adapter needs to stop */ - bool ipv6enabled; /**< IPv6 enabled by OCInit flags */ - bool ipv4enabled; /**< IPv4 enabled by OCInit flags */ - bool dualstack; /**< IPv6 and IPv4 enabled */ + void *threadpool; /**< threadpool between Initialize and Start */ + CASocket_t u6; /**< unicast IPv6 */ + CASocket_t u6s; /**< unicast IPv6 secure */ + CASocket_t u4; /**< unicast IPv4 */ + CASocket_t u4s; /**< unicast IPv4 secure */ + CASocket_t m6; /**< multicast IPv6 */ + CASocket_t m6s; /**< multicast IPv6 secure */ + CASocket_t m4; /**< multicast IPv4 */ + CASocket_t m4s; /**< multicast IPv4 secure */ + int netlinkFd; /**< netlink */ +#if defined(_WIN32) + WSAEVENT shutdownEvent; /**< Event used to signal threads to stop */ +#else + int shutdownFds[2]; /**< fds used to signal threads to stop */ +#endif + int selectTimeout; /**< in seconds */ + int maxfd; /**< highest fd (for select) */ + bool started; /**< the IP adapter has started */ + bool terminate; /**< the IP adapter needs to stop */ + bool ipv6enabled; /**< IPv6 enabled by OCInit flags */ + bool ipv4enabled; /**< IPv4 enabled by OCInit flags */ + bool dualstack; /**< IPv6 and IPv4 enabled */ +#if defined (_WIN32) + LPFN_WSARECVMSG wsaRecvMsg; /**< Win32 function pointer to WSARecvMsg() */ +#endif struct networkmonitors { diff --cc resource/csdk/connectivity/src/ip_adapter/caipserver.c index 6a9cb97,e310c92..c162a19 --- a/resource/csdk/connectivity/src/ip_adapter/caipserver.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipserver.c @@@ -117,33 -96,12 +117,32 @@@ static char *ipv6mcnames[IPv6_DOMAINS] NULL }; -static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL; +#if defined (_WIN32) +#define IFF_UP_RUNNING_FLAGS (IFF_UP) + char* caips_get_error(){ + static char buffer[32]; + snprintf(buffer, 32, "%i", WSAGetLastError()); + return buffer; + } +#define CAIPS_GET_ERROR \ + caips_get_error() +#else +#define IFF_UP_RUNNING_FLAGS (IFF_UP|IFF_RUNNING) + +#define CAIPS_GET_ERROR \ + strerror(errno) +#endif static CAIPErrorHandleCallback g_ipErrorHandler = NULL; +static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL; + - static void CAHandleNetlink(); static void CAFindReadyMessage(); +#if !defined(WSA_WAIT_EVENT_0) static void CASelectReturned(fd_set *readFds, int ret); +#else +static void CAEventReturned(HANDLE); +#endif static void CAProcessNewInterface(CAInterface_t *ifchanged); static CAResult_t CAReceiveMessage(int fd, CATransportFlags_t flags); @@@ -675,20 -390,16 +674,20 @@@ static int CACreateSocket(int family, u { int on = 1; - if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on))) + if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&on), sizeof (on))) { - OIC_LOG_V(ERROR, TAG, "IPV6_V6ONLY failed: %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "IPV6_V6ONLY failed: %s", CAIPS_GET_ERROR); } - if (*port) // only do this for multicast ports - if (isMulticast && *port) // only do this for multicast ports ++ if (isMulticast && *port) // only do this for multicast ports { +#if defined(IPV6_RECVPKTINFO) if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof (on))) +#else + if (-1 == setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, OPTVAL_T(&on), sizeof (on))) +#endif { - OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "IPV6_RECVPKTINFO failed: %s",CAIPS_GET_ERROR); } } @@@ -697,12 -408,12 +696,12 @@@ } else { - if (*port) // only do this for multicast ports - if (isMulticast && *port) // only do this for multicast ports ++ if (isMulticast && *port) // only do this for multicast ports { int on = 1; - if (-1 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &on, sizeof (on))) + if (-1 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, OPTVAL_T(&on), sizeof (on))) { - OIC_LOG_V(ERROR, TAG, "IP_PKTINFO failed: %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "IP_PKTINFO failed: %s", CAIPS_GET_ERROR); } } @@@ -710,17 -421,13 +709,17 @@@ socklen = sizeof (struct sockaddr_in); } - if (*port) // use the given port - if (isMulticast && *port) // use the given port ++ if (isMulticast && *port) // use the given port { int on = 1; - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on))) + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on), sizeof (on))) { - OIC_LOG_V(ERROR, TAG, "SO_REUSEADDR failed: %s", strerror(errno)); + OIC_LOG_V(ERROR, TAG, "SO_REUSEADDR failed: %s", CAIPS_GET_ERROR); +#ifdef _WIN32 + closesocket(fd); +#else close(fd); +#endif return -1; } } diff --cc resource/src/CAManager.cpp index d25d70f,740ded3..59cba9a --- a/resource/src/CAManager.cpp +++ b/resource/src/CAManager.cpp @@@ -33,10 -33,27 +33,27 @@@ using namespace OC namespace { - CAManager::AdapterChangedCallback g_adapterHandler = NULL; - CAManager::ConnectionChangedCallback g_connectionHandler = NULL; + CAManager::AdapterChangedCallback g_adapterHandler = nullptr; + CAManager::ConnectionChangedCallback g_connectionHandler = nullptr; } + OCStackResult convertCAResultToOCResult(CAResult_t caResult) + { + switch (caResult) + { + case CA_STATUS_OK: + return OC_STACK_OK; + case CA_STATUS_INVALID_PARAM: + return OC_STACK_INVALID_PARAM; + case CA_STATUS_FAILED: + return OC_STACK_ERROR; + case CA_NOT_SUPPORTED: + return OC_STACK_NOTIMPL; + default: + return OC_STACK_ERROR; + } + } + void DefaultAdapterStateChangedHandler(CATransportAdapter_t adapter, bool enabled) { if (g_adapterHandler)