这篇教程C++ win_assert函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中win_assert函数的典型用法代码示例。如果您正苦于以下问题:C++ win_assert函数的具体用法?C++ win_assert怎么用?C++ win_assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了win_assert函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: WaitForSingleObjectvoid xs::thread_stop (xs::thread_t *self_){ DWORD rc = WaitForSingleObject (self_->handle, INFINITE); win_assert (rc != WAIT_FAILED); BOOL rc2 = CloseHandle (self_->handle); win_assert (rc2 != 0);}
开发者ID:adeze,项目名称:libxs,代码行数:7,
示例2: WaitForSingleObjectvoid zmq::thread_t::stop (){ DWORD rc = WaitForSingleObject (descriptor, INFINITE); win_assert (rc != WAIT_FAILED); BOOL rc2 = CloseHandle (descriptor); win_assert (rc2 != 0);}
开发者ID:HJoYer,项目名称:libzmq,代码行数:7,
示例3: socketzmq::fd_t zmq::open_socket (int domain_, int type_, int protocol_){ // Setting this option result in sane behaviour when exec() functions // are used. Old sockets are closed and don't block TCP ports etc.#if defined ZMQ_HAVE_SOCK_CLOEXEC type_ |= SOCK_CLOEXEC;#endif fd_t s = socket (domain_, type_, protocol_);#ifdef ZMQ_HAVE_WINDOWS if (s == INVALID_SOCKET) return INVALID_SOCKET;#else if (s == -1) return -1;#endif // If there's no SOCK_CLOEXEC, let's try the second best option. Note that // race condition can cause socket not to be closed (if fork happens // between socket creation and this point).#if !defined ZMQ_HAVE_SOCK_CLOEXEC && defined FD_CLOEXEC int rc = fcntl (s, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1);#endif // On Windows, preventing sockets to be inherited by child processes.#if defined ZMQ_HAVE_WINDOWS && defined HANDLE_FLAG_INHERIT BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0); win_assert (brc);#endif return s;}
开发者ID:0x6d686b,项目名称:libzmq,代码行数:33,
示例4: nn_sem_postvoid nn_sem_post (struct nn_sem *myself){ BOOL brc; brc = SetEvent (myself->h); win_assert (brc);}
开发者ID:Miyurz,项目名称:SuperNET,代码行数:7,
示例5: nn_sem_termvoid nn_sem_term (struct nn_sem *myself){ BOOL brc; brc = CloseHandle (myself->h); win_assert (brc);}
开发者ID:Miyurz,项目名称:SuperNET,代码行数:7,
示例6: zmq_assertzmq::fd_t zmq::tcp_listener_t::accept (){ // The situation where connection cannot be accepted due to insufficient // resources is considered valid and treated by ignoring the connection. // Accept one connection and deal with different failure modes. zmq_assert (s != retired_fd); struct sockaddr_storage ss; memset (&ss, 0, sizeof (ss));#ifdef ZMQ_HAVE_HPUX int ss_len = sizeof (ss);#else socklen_t ss_len = sizeof (ss);#endif fd_t sock = ::accept (s, (struct sockaddr *) &ss, &ss_len);#ifdef ZMQ_HAVE_WINDOWS if (sock == INVALID_SOCKET) { wsa_assert (WSAGetLastError () == WSAEWOULDBLOCK || WSAGetLastError () == WSAECONNRESET || WSAGetLastError () == WSAEMFILE || WSAGetLastError () == WSAENOBUFS); return retired_fd; } // On Windows, preventing sockets to be inherited by child processes. BOOL brc = SetHandleInformation ((HANDLE) sock, HANDLE_FLAG_INHERIT, 0); win_assert (brc);#else if (sock == -1) { errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ECONNABORTED || errno == EPROTO || errno == ENOBUFS || errno == ENOMEM || errno == EMFILE || errno == ENFILE); return retired_fd; }#endif if (!options.tcp_accept_filters.empty ()) { bool matched = false; for (options_t::tcp_accept_filters_t::size_type i = 0; i != options.tcp_accept_filters.size (); ++i) { if (options.tcp_accept_filters[i].match_address ((struct sockaddr *) &ss, ss_len)) { matched = true; break; } } if (!matched) {#ifdef ZMQ_HAVE_WINDOWS int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR);#else int rc = ::close (sock); errno_assert (rc == 0);#endif return retired_fd; } } return sock;}
开发者ID:coldeasy,项目名称:libzmq,代码行数:59,
示例7: _beginthreadexvoid zmq::thread_t::start (thread_fn *tfn_, void *arg_){ tfn = tfn_; arg =arg_; descriptor = (HANDLE) _beginthreadex (NULL, 0, &::thread_routine, this, 0 , NULL); win_assert (descriptor != NULL);}
开发者ID:EvgeniyRudnev,项目名称:tatengine,代码行数:8,
示例8: _beginthreadexvoid xs::thread_start (xs::thread_t *self_, thread_fn *tfn_, void *arg_){ self_->tfn = tfn_; self_->arg =arg_; self_->handle = (HANDLE) _beginthreadex (NULL, 0, &::thread_routine, self_, 0 , NULL); win_assert (self_->handle != NULL); }
开发者ID:adeze,项目名称:libxs,代码行数:8,
示例9: sizeofvoid zmq::signaler_t::send (const command_t &cmd_){ // TODO: Note that send is a blocking operation. // How should we behave if the signal cannot be written to the signaler? // Even worse: What if half of a command is written? int rc = ::send (w, (char*) &cmd_, sizeof (command_t), 0); win_assert (rc != SOCKET_ERROR); zmq_assert (rc == sizeof (command_t));}
开发者ID:dell-esdk,项目名称:zeromq2,代码行数:9,
示例10: nn_sem_waitint nn_sem_wait (struct nn_sem *myself){ DWORD rc; rc = WaitForSingleObject (myself->h, INFINITE); win_assert (rc != WAIT_FAILED); nn_assert (rc == WAIT_OBJECT_0); return 0;}
开发者ID:Miyurz,项目名称:SuperNET,代码行数:10,
示例11: CreateThreadvoid zmq::thread_t::start (thread_fn *tfn_, void *arg_){ tfn = tfn_; arg = arg_;#if defined _WIN32_WCE descriptor = (HANDLE) CreateThread (NULL, 0, &::thread_routine, this, 0 , NULL);#else descriptor = (HANDLE) _beginthreadex (NULL, 0, &::thread_routine, this, 0 , NULL);#endif win_assert (descriptor != NULL); }
开发者ID:HJoYer,项目名称:libzmq,代码行数:13,
示例12: wait inline int wait (mutex_t* mutex_, int timeout_ ) { int rc = SleepConditionVariableCS(&cv, mutex_->get_cs (), timeout_); if (rc != 0) return 0; rc = GetLastError(); if (rc != ERROR_TIMEOUT) win_assert(rc); errno = EAGAIN; return -1; }
开发者ID:GameFilebyOpenSourse,项目名称:libzmq,代码行数:15,
示例13: SetHandleInformationvoid zmq::make_socket_noninheritable (fd_t sock){#if defined ZMQ_HAVE_WINDOWS && !defined _WIN32_WCE / && !defined ZMQ_HAVE_WINDOWS_UWP // On Windows, preventing sockets to be inherited by child processes. const BOOL brc = SetHandleInformation (reinterpret_cast<HANDLE> (sock), HANDLE_FLAG_INHERIT, 0); win_assert (brc);#endif#if (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) / && defined FD_CLOEXEC // If there 's no SOCK_CLOEXEC, let's try the second best option. // Race condition can cause socket not to be closed (if fork happens // between accept and this point). const int rc = fcntl (sock, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1);#endif}
开发者ID:ming-hai,项目名称:libzmq,代码行数:19,
示例14: zmq_assertzmq::fd_t zmq::vmci_listener_t::accept (){ // Accept one connection and deal with different failure modes. // The situation where connection cannot be accepted due to insufficient // resources is considered valid and treated by ignoring the connection. zmq_assert (s != retired_fd); fd_t sock = ::accept (s, NULL, NULL);#ifdef ZMQ_HAVE_WINDOWS if (sock == INVALID_SOCKET) { wsa_assert(WSAGetLastError() == WSAEWOULDBLOCK || WSAGetLastError() == WSAECONNRESET || WSAGetLastError() == WSAEMFILE || WSAGetLastError() == WSAENOBUFS); return retired_fd; }#if !defined _WIN32_WCE // On Windows, preventing sockets to be inherited by child processes. BOOL brc = SetHandleInformation((HANDLE)sock, HANDLE_FLAG_INHERIT, 0); win_assert(brc);#endif#else if (sock == -1) { errno_assert(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ECONNABORTED || errno == EPROTO || errno == ENOBUFS || errno == ENOMEM || errno == EMFILE || errno == ENFILE); return retired_fd; }#endif // Race condition can cause socket not to be closed (if fork happens // between accept and this point).#ifdef FD_CLOEXEC int rc = fcntl (sock, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1);#endif return sock;}
开发者ID:5igm4,项目名称:libzmq,代码行数:40,
示例15: zmq_assertzmq::fd_t zmq::tcp_listener_t::accept (){ // The situation where connection cannot be accepted due to insufficient // resources is considered valid and treated by ignoring the connection. // Accept one connection and deal with different failure modes. zmq_assert (s != retired_fd); struct sockaddr_storage ss; memset (&ss, 0, sizeof (ss));#ifdef ZMQ_HAVE_HPUX int ss_len = sizeof (ss);#else socklen_t ss_len = sizeof (ss);#endif#if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4 fd_t sock = ::accept4 (s, (struct sockaddr *) &ss, &ss_len, SOCK_CLOEXEC);#else fd_t sock = ::accept (s, (struct sockaddr *) &ss, &ss_len);#endif#ifdef ZMQ_HAVE_WINDOWS if (sock == INVALID_SOCKET) { const int last_error = WSAGetLastError (); wsa_assert (last_error == WSAEWOULDBLOCK || last_error == WSAECONNRESET || last_error == WSAEMFILE || last_error == WSAENOBUFS); return retired_fd; }#if !defined _WIN32_WCE && !defined ZMQ_HAVE_WINDOWS_UWP // On Windows, preventing sockets to be inherited by child processes. BOOL brc = SetHandleInformation ((HANDLE) sock, HANDLE_FLAG_INHERIT, 0); win_assert (brc);#endif#else if (sock == -1) { errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ECONNABORTED || errno == EPROTO || errno == ENOBUFS || errno == ENOMEM || errno == EMFILE || errno == ENFILE); return retired_fd; }#endif#if (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) / && defined FD_CLOEXEC // Race condition can cause socket not to be closed (if fork happens // between accept and this point). int rc = fcntl (sock, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1);#endif if (!options.tcp_accept_filters.empty ()) { bool matched = false; for (options_t::tcp_accept_filters_t::size_type i = 0; i != options.tcp_accept_filters.size (); ++i) { if (options.tcp_accept_filters[i].match_address ( (struct sockaddr *) &ss, ss_len)) { matched = true; break; } } if (!matched) {#ifdef ZMQ_HAVE_WINDOWS int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR);#else int rc = ::close (sock); errno_assert (rc == 0);#endif return retired_fd; } } if (zmq::set_nosigpipe (sock)) {#ifdef ZMQ_HAVE_WINDOWS int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR);#else int rc = ::close (sock); errno_assert (rc == 0);#endif return retired_fd; } // Set the IP Type-Of-Service priority for this client socket if (options.tos != 0) set_ip_type_of_service (sock, options.tos); return sock;}
开发者ID:cuijw,项目名称:libzmq,代码行数:89,
示例16: open_socketint zmq::tcp_listener_t::set_address (const char *addr_){ // Convert the textual address into address structure. int rc = address.resolve (addr_, true, options.ipv6); if (rc != 0) return -1; address.to_string (endpoint); if (options.use_fd != -1) { s = options.use_fd; socket->event_listening (endpoint, (int) s); return 0; } // Create a listening socket. s = open_socket (address.family (), SOCK_STREAM, IPPROTO_TCP); // IPv6 address family not supported, try automatic downgrade to IPv4. if (s == zmq::retired_fd && address.family () == AF_INET6 && errno == EAFNOSUPPORT && options.ipv6) { rc = address.resolve (addr_, true, false); if (rc != 0) return rc; s = open_socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); }#ifdef ZMQ_HAVE_WINDOWS if (s == INVALID_SOCKET) { errno = wsa_error_to_errno (WSAGetLastError ()); return -1; }#if !defined _WIN32_WCE && !defined ZMQ_HAVE_WINDOWS_UWP // On Windows, preventing sockets to be inherited by child processes. BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0); win_assert (brc);#endif#else if (s == -1) return -1;#endif // On some systems, IPv4 mapping in IPv6 sockets is disabled by default. // Switch it on in such cases. if (address.family () == AF_INET6) enable_ipv4_mapping (s); // Set the IP Type-Of-Service for the underlying socket if (options.tos != 0) set_ip_type_of_service (s, options.tos); // Set the socket to loopback fastpath if configured. if (options.loopback_fastpath) tcp_tune_loopback_fast_path (s); // Bind the socket to a device if applicable if (!options.bound_device.empty ()) bind_to_device (s, options.bound_device); // Set the socket buffer limits for the underlying socket. if (options.sndbuf >= 0) set_tcp_send_buffer (s, options.sndbuf); if (options.rcvbuf >= 0) set_tcp_receive_buffer (s, options.rcvbuf); // Allow reusing of the address. int flag = 1;#ifdef ZMQ_HAVE_WINDOWS rc = setsockopt (s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (const char *) &flag, sizeof (int)); wsa_assert (rc != SOCKET_ERROR);#else rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)); errno_assert (rc == 0);#endif // Bind the socket to the network interface and port. rc = bind (s, address.addr (), address.addrlen ());#ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); goto error; }#else if (rc != 0) goto error;#endif // Listen for incoming connections. rc = listen (s, options.backlog);#ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); goto error; }#else if (rc != 0) goto error;#endif//.........这里部分代码省略.........
开发者ID:cuijw,项目名称:libzmq,代码行数:101,
示例17: eventfdint zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_){#if defined ZMQ_HAVE_EVENTFD // Create eventfd object. fd_t fd = eventfd (0, 0); errno_assert (fd != -1); *w_ = fd; *r_ = fd; return 0;#elif defined ZMQ_HAVE_WINDOWS // This function has to be in a system-wide critical section so that // two instances of the library don't accidentally create signaler // crossing the process boundary. // We'll use named event object to implement the critical section. // Note that if the event object already exists, the CreateEvent requests // EVENT_ALL_ACCESS access right. If this fails, we try to open // the event object asking for SYNCHRONIZE access only. HANDLE sync = CreateEvent (NULL, FALSE, TRUE, TEXT ("zmq-signaler-port-sync")); if (sync == NULL && GetLastError () == ERROR_ACCESS_DENIED) sync = OpenEvent (SYNCHRONIZE, FALSE, TEXT ("zmq-signaler-port-sync")); win_assert (sync != NULL); // Enter the critical section. DWORD dwrc = WaitForSingleObject (sync, INFINITE); zmq_assert (dwrc == WAIT_OBJECT_0); // Windows has no 'socketpair' function. CreatePipe is no good as pipe // handles cannot be polled on. Here we create the socketpair by hand. *w_ = INVALID_SOCKET; *r_ = INVALID_SOCKET; // Create listening socket. SOCKET listener; listener = open_socket (AF_INET, SOCK_STREAM, 0); wsa_assert (listener != INVALID_SOCKET); // Set SO_REUSEADDR and TCP_NODELAY on listening socket. BOOL so_reuseaddr = 1; int rc = setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, (char *)&so_reuseaddr, sizeof (so_reuseaddr)); wsa_assert (rc != SOCKET_ERROR); BOOL tcp_nodelay = 1; rc = setsockopt (listener, IPPROTO_TCP, TCP_NODELAY, (char *)&tcp_nodelay, sizeof (tcp_nodelay)); wsa_assert (rc != SOCKET_ERROR); // Bind listening socket to any free local port. struct sockaddr_in addr; memset (&addr, 0, sizeof (addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (signaler_port); rc = bind (listener, (const struct sockaddr*) &addr, sizeof (addr)); wsa_assert (rc != SOCKET_ERROR); // Listen for incomming connections. rc = listen (listener, 1); wsa_assert (rc != SOCKET_ERROR); // Create the writer socket. *w_ = WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, 0); wsa_assert (*w_ != INVALID_SOCKET); // Set TCP_NODELAY on writer socket. rc = setsockopt (*w_, IPPROTO_TCP, TCP_NODELAY, (char *)&tcp_nodelay, sizeof (tcp_nodelay)); wsa_assert (rc != SOCKET_ERROR); // Connect writer to the listener. rc = connect (*w_, (sockaddr *) &addr, sizeof (addr)); wsa_assert (rc != SOCKET_ERROR); // Accept connection from writer. *r_ = accept (listener, NULL, NULL); wsa_assert (*r_ != INVALID_SOCKET); // We don't need the listening socket anymore. Close it. rc = closesocket (listener); wsa_assert (rc != SOCKET_ERROR); // Exit the critical section. BOOL brc = SetEvent (sync); win_assert (brc != 0); return 0;#elif defined ZMQ_HAVE_OPENVMS // Whilst OpenVMS supports socketpair - it maps to AF_INET only. Further, // it does not set the socket options TCP_NODELAY and TCP_NODELACK which // can lead to performance problems. // // The bug will be fixed in V5.6 ECO4 and beyond. In the meantime, we'll // create the socket pair manually. sockaddr_in lcladdr; memset (&lcladdr, 0, sizeof (lcladdr));//.........这里部分代码省略.........
开发者ID:phoehne,项目名称:ZeroMQKit,代码行数:101,
示例18: WaitForSingleObjectvoid zmq::thread_t::stop (){ DWORD rc = WaitForSingleObject (descriptor, INFINITE); win_assert (rc != WAIT_FAILED);}
开发者ID:PVanV,项目名称:zeromq1,代码行数:5,
示例19: open_socketint zmq::tcp_listener_t::set_address (const char *addr_){ // Convert the textual address into address structure. int rc = address.resolve (addr_, true, options.ipv4only ? true : false); if (rc != 0) return -1; // Create a listening socket. s = open_socket (address.family (), SOCK_STREAM, IPPROTO_TCP);#ifdef ZMQ_HAVE_WINDOWS if (s == INVALID_SOCKET) errno = wsa_error_to_errno (WSAGetLastError ());#endif // IPv6 address family not supported, try automatic downgrade to IPv4. if (address.family () == AF_INET6 && errno == EAFNOSUPPORT && !options.ipv4only) { rc = address.resolve (addr_, true, true); if (rc != 0) return rc; s = ::socket (address.family (), SOCK_STREAM, IPPROTO_TCP); }#ifdef ZMQ_HAVE_WINDOWS if (s == INVALID_SOCKET) { errno = wsa_error_to_errno (WSAGetLastError ()); return -1; } // On Windows, preventing sockets to be inherited by child processes. BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0); win_assert (brc);#else if (s == -1) return -1;#endif // On some systems, IPv4 mapping in IPv6 sockets is disabled by default. // Switch it on in such cases. if (address.family () == AF_INET6) enable_ipv4_mapping (s); // Allow reusing of the address. int flag = 1;#ifdef ZMQ_HAVE_WINDOWS rc = setsockopt (s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (const char*) &flag, sizeof (int)); wsa_assert (rc != SOCKET_ERROR);#else rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)); errno_assert (rc == 0);#endif address.to_string (endpoint); // Bind the socket to the network interface and port. rc = bind (s, address.addr (), address.addrlen ());#ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); return -1; }#else if (rc != 0) return -1;#endif // Listen for incomming connections. rc = listen (s, options.backlog);#ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); return -1; }#else if (rc != 0) return -1;#endif socket->monitor_event (ZMQ_EVENT_LISTENING, addr_, s); return 0;}
开发者ID:DeadZen,项目名称:CloudI,代码行数:81,
示例20: nn_sem_initvoid nn_sem_init (struct nn_sem *myself){ myself->h = CreateEvent (NULL, FALSE, FALSE, NULL); win_assert (myself->h);}
开发者ID:Miyurz,项目名称:SuperNET,代码行数:5,
示例21: make_fdpairstatic int make_fdpair (xs::fd_t *r_, xs::fd_t *w_){#if defined XS_HAVE_EVENTFD // Create eventfd object.#if defined EFD_CLOEXEC xs::fd_t fd = eventfd (0, EFD_CLOEXEC); if (fd == -1) return -1;#else xs::fd_t fd = eventfd (0, 0); if (fd == -1) return -1;#if defined FD_CLOEXEC int rc = fcntl (fd, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1);#endif#endif *w_ = fd; *r_ = fd; return 0;#elif defined XS_HAVE_WINDOWS // On Windows we are using TCP sockets for in-process communication. // That is a security hole -- other processes on the same box may connect // to the bound TCP port and hook into internal signal processing of // the library. To solve this problem we should use a proper in-process // signaling mechanism such as private semaphore. However, on Windows, // these cannot be polled on using select(). Other functions that allow // polling on these objects (e.g. WaitForMulitpleObjects) don't allow // to poll on sockets. Thus, the only way to fix the problem is to // implement IOCP polling mechanism that allows to poll on both sockets // and in-process synchronisation objects. // Make the following critical section accessible to everyone. SECURITY_ATTRIBUTES sa = {0}; sa.nLength = sizeof (sa); sa.bInheritHandle = FALSE; SECURITY_DESCRIPTOR sd; BOOL ok = InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION); win_assert (ok); ok = SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE); win_assert (ok); sa.lpSecurityDescriptor = &sd; // This function has to be in a system-wide critical section so that // two instances of the library don't accidentally create signaler // crossing the process boundary. HANDLE sync = CreateEvent (&sa, FALSE, TRUE, "Global//xs-signaler-port-sync"); win_assert (sync != NULL); // Enter the critical section. DWORD dwrc = WaitForSingleObject (sync, INFINITE); xs_assert (dwrc == WAIT_OBJECT_0); // Windows has no 'socketpair' function. CreatePipe is no good as pipe // handles cannot be polled on. Here we create the socketpair by hand. *w_ = INVALID_SOCKET; *r_ = INVALID_SOCKET; // Create listening socket. SOCKET listener; listener = xs::open_socket (AF_INET, SOCK_STREAM, 0); if (listener == xs::retired_fd) { BOOL brc = SetEvent (sync); win_assert (brc != 0); return -1; } // Set SO_REUSEADDR and TCP_NODELAY on listening socket. BOOL so_reuseaddr = 1; int rc = setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, (char *)&so_reuseaddr, sizeof (so_reuseaddr)); if (rc == SOCKET_ERROR) { BOOL brc = SetEvent (sync); win_assert (brc != 0); xs_assert (false); } BOOL tcp_nodelay = 1; rc = setsockopt (listener, IPPROTO_TCP, TCP_NODELAY, (char *)&tcp_nodelay, sizeof (tcp_nodelay)); if (rc == SOCKET_ERROR) { BOOL brc = SetEvent (sync); win_assert (brc != 0); xs_assert (false); } // Bind listening socket to the local port. struct sockaddr_in addr; memset (&addr, 0, sizeof (addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (xs::signaler_port); rc = bind (listener, (const struct sockaddr*) &addr, sizeof (addr)); if (rc == SOCKET_ERROR) { BOOL brc = SetEvent (sync); win_assert (brc != 0); xs_assert (false);//.........这里部分代码省略.........
开发者ID:adeze,项目名称:libxs,代码行数:101,
示例22: addrint zmq::vmci_listener_t::set_address (const char *addr_){ // Create addr on stack for auto-cleanup std::string addr (addr_); // Initialise the address structure. vmci_address_t address(this->get_ctx ()); int rc = address.resolve (addr.c_str()); if (rc != 0) return -1; // Create a listening socket. s = open_socket (this->get_ctx ()->get_vmci_socket_family (), SOCK_STREAM, 0);#ifdef ZMQ_HAVE_WINDOWS if (s == INVALID_SOCKET) { errno = wsa_error_to_errno(WSAGetLastError()); return -1; }#if !defined _WIN32_WCE // On Windows, preventing sockets to be inherited by child processes. BOOL brc = SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); win_assert(brc);#endif#else if (s == -1) return -1;#endif address.to_string (endpoint); // Bind the socket. rc = bind (s, address.addr (), address.addrlen ());#ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno(WSAGetLastError()); goto error; }#else if (rc != 0) goto error;#endif // Listen for incoming connections. rc = listen (s, options.backlog);#ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno(WSAGetLastError()); goto error; }#else if (rc != 0) goto error;#endif socket->event_listening (endpoint, s); return 0; error: int err = errno; close (); errno = err; return -1;}
开发者ID:5igm4,项目名称:libzmq,代码行数:63,
示例23: wait // Wait for the semaphore. inline void wait () { DWORD rc = WaitForSingleObject (ev, INFINITE); win_assert (rc != WAIT_FAILED); }
开发者ID:EvgeniyRudnev,项目名称:tatengine,代码行数:6,
示例24: CloseHandle // Destroy the semaphore. inline ~semaphore_t () { int rc = CloseHandle (ev); win_assert (rc != 0); }
开发者ID:EvgeniyRudnev,项目名称:tatengine,代码行数:6,
示例25: eventfd// Returns -1 if we could not make the socket pair successfullyint zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_){#if defined ZMQ_HAVE_EVENTFD fd_t fd = eventfd (0, 0); if (fd == -1) { errno_assert (errno == ENFILE || errno == EMFILE); *w_ = *r_ = -1; return -1; } else { *w_ = *r_ = fd; return 0; }#elif defined ZMQ_HAVE_WINDOWS# if !defined _WIN32_WCE // Windows CE does not manage security attributes SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sa; memset (&sd, 0, sizeof (sd)); memset (&sa, 0, sizeof (sa)); InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE); sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = &sd;# endif // This function has to be in a system-wide critical section so that // two instances of the library don't accidentally create signaler // crossing the process boundary. // We'll use named event object to implement the critical section. // Note that if the event object already exists, the CreateEvent requests // EVENT_ALL_ACCESS access right. If this fails, we try to open // the event object asking for SYNCHRONIZE access only. HANDLE sync = NULL; // Create critical section only if using fixed signaler port // Use problematic Event implementation for compatibility if using old port 5905. // Otherwise use Mutex implementation. int event_signaler_port = 5905; if (signaler_port == event_signaler_port) {# if !defined _WIN32_WCE sync = CreateEvent (&sa, FALSE, TRUE, TEXT ("Global//zmq-signaler-port-sync"));# else sync = CreateEvent (NULL, FALSE, TRUE, TEXT ("Global//zmq-signaler-port-sync"));# endif if (sync == NULL && GetLastError () == ERROR_ACCESS_DENIED) sync = OpenEvent (SYNCHRONIZE | EVENT_MODIFY_STATE, FALSE, TEXT ("Global//zmq-signaler-port-sync")); win_assert (sync != NULL); } else if (signaler_port != 0) { TCHAR mutex_name[64]; /* VC++ v120 swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. */ _stprintf (mutex_name, TEXT ("Global//zmq-signaler-port-%d"), signaler_port);# if !defined _WIN32_WCE sync = CreateMutex (&sa, FALSE, mutex_name);# else sync = CreateMutex (NULL, FALSE, mutex_name);# endif if (sync == NULL && GetLastError () == ERROR_ACCESS_DENIED) sync = OpenMutex (SYNCHRONIZE, FALSE, mutex_name); win_assert (sync != NULL); } // Windows has no 'socketpair' function. CreatePipe is no good as pipe // handles cannot be polled on. Here we create the socketpair by hand. *w_ = INVALID_SOCKET; *r_ = INVALID_SOCKET; // Create listening socket. SOCKET listener; listener = open_socket (AF_INET, SOCK_STREAM, 0); wsa_assert (listener != INVALID_SOCKET); // Set SO_REUSEADDR and TCP_NODELAY on listening socket. BOOL so_reuseaddr = 1; int rc = setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, (char *)&so_reuseaddr, sizeof (so_reuseaddr)); wsa_assert (rc != SOCKET_ERROR); BOOL tcp_nodelay = 1; rc = setsockopt (listener, IPPROTO_TCP, TCP_NODELAY, (char *)&tcp_nodelay, sizeof (tcp_nodelay)); wsa_assert (rc != SOCKET_ERROR); // Init sockaddr to signaler port. struct sockaddr_in addr; memset (&addr, 0, sizeof (addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (signaler_port);//.........这里部分代码省略.........
开发者ID:FlavioFalcao,项目名称:libzmq,代码行数:101,
示例26: post // Post the semaphore. inline void post () { int rc = SetEvent (ev); win_assert (rc != 0); }
开发者ID:EvgeniyRudnev,项目名称:tatengine,代码行数:6,
示例27: eventfdint zmq::make_fdpair (fd_t *r_, fd_t *w_){#if defined ZMQ_HAVE_EVENTFD int flags = 0;#if defined ZMQ_HAVE_EVENTFD_CLOEXEC // Setting this option result in sane behaviour when exec() functions // are used. Old sockets are closed and don't block TCP ports, avoid // leaks, etc. flags |= EFD_CLOEXEC;#endif fd_t fd = eventfd (0, flags); if (fd == -1) { errno_assert (errno == ENFILE || errno == EMFILE); *w_ = *r_ = -1; return -1; } else { *w_ = *r_ = fd; return 0; }#elif defined ZMQ_HAVE_WINDOWS#if !defined _WIN32_WCE && !defined ZMQ_HAVE_WINDOWS_UWP // Windows CE does not manage security attributes SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sa; memset (&sd, 0, sizeof sd); memset (&sa, 0, sizeof sa); InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl (&sd, TRUE, 0, FALSE); sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = &sd;#endif // This function has to be in a system-wide critical section so that // two instances of the library don't accidentally create signaler // crossing the process boundary. // We'll use named event object to implement the critical section. // Note that if the event object already exists, the CreateEvent requests // EVENT_ALL_ACCESS access right. If this fails, we try to open // the event object asking for SYNCHRONIZE access only. HANDLE sync = NULL; // Create critical section only if using fixed signaler port // Use problematic Event implementation for compatibility if using old port 5905. // Otherwise use Mutex implementation. int event_signaler_port = 5905; if (signaler_port == event_signaler_port) {#if !defined _WIN32_WCE && !defined ZMQ_HAVE_WINDOWS_UWP sync = CreateEventW (&sa, FALSE, TRUE, L"Global//zmq-signaler-port-sync");#else sync = CreateEventW (NULL, FALSE, TRUE, L"Global//zmq-signaler-port-sync");#endif if (sync == NULL && GetLastError () == ERROR_ACCESS_DENIED) sync = OpenEventW (SYNCHRONIZE | EVENT_MODIFY_STATE, FALSE, L"Global//zmq-signaler-port-sync"); win_assert (sync != NULL); } else if (signaler_port != 0) { wchar_t mutex_name[MAX_PATH];#ifdef __MINGW32__ _snwprintf (mutex_name, MAX_PATH, L"Global//zmq-signaler-port-%d", signaler_port);#else swprintf (mutex_name, MAX_PATH, L"Global//zmq-signaler-port-%d", signaler_port);#endif#if !defined _WIN32_WCE && !defined ZMQ_HAVE_WINDOWS_UWP sync = CreateMutexW (&sa, FALSE, mutex_name);#else sync = CreateMutexW (NULL, FALSE, mutex_name);#endif if (sync == NULL && GetLastError () == ERROR_ACCESS_DENIED) sync = OpenMutexW (SYNCHRONIZE, FALSE, mutex_name); win_assert (sync != NULL); } // Windows has no 'socketpair' function. CreatePipe is no good as pipe // handles cannot be polled on. Here we create the socketpair by hand. *w_ = INVALID_SOCKET; *r_ = INVALID_SOCKET; // Create listening socket. SOCKET listener; listener = open_socket (AF_INET, SOCK_STREAM, 0); wsa_assert (listener != INVALID_SOCKET); // Set SO_REUSEADDR and TCP_NODELAY on listening socket. BOOL so_reuseaddr = 1; int rc = setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, (char *) &so_reuseaddr, sizeof so_reuseaddr); wsa_assert (rc != SOCKET_ERROR); tune_socket (listener);//.........这里部分代码省略.........
开发者ID:cuijw,项目名称:libzmq,代码行数:101,
示例28: semaphore_t // Initialise the semaphore. inline semaphore_t () { ev = CreateEvent (NULL, FALSE, FALSE, NULL); win_assert (ev != NULL); }
开发者ID:EvgeniyRudnev,项目名称:tatengine,代码行数:6,
注:本文中的win_assert函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ win_compopup_init函数代码示例 C++ winScreenPriv函数代码示例 |