本文整理汇总了C++中StreamSocket::GetIOHook方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamSocket::GetIOHook方法的具体用法?C++ StreamSocket::GetIOHook怎么用?C++ StreamSocket::GetIOHook使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamSocket
的用法示例。
在下文中一共展示了StreamSocket::GetIOHook方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gnutls_push_wrapper
static ssize_t gnutls_push_wrapper(gnutls_transport_ptr_t session_wrap, const void* buffer, size_t size)
{
StreamSocket* sock = reinterpret_cast<StreamSocket*>(session_wrap);
#ifdef _WIN32
GnuTLSIOHook* session = static_cast<GnuTLSIOHook*>(sock->GetIOHook());
#endif
if (sock->GetEventMask() & FD_WRITE_WILL_BLOCK)
{
#ifdef _WIN32
gnutls_transport_set_errno(session->sess, EAGAIN);
#else
errno = EAGAIN;
#endif
return -1;
}
int rv = SocketEngine::Send(sock, reinterpret_cast<const char *>(buffer), size, 0);
#ifdef _WIN32
if (rv < 0)
{
/* Windows doesn't use errno, but gnutls does, so check SocketEngine::IgnoreError()
* and then set errno appropriately.
* The gnutls library may also have a different errno variable than us, see
* gnutls_transport_set_errno(3).
*/
gnutls_transport_set_errno(session->sess, SocketEngine::IgnoreError() ? EAGAIN : errno);
}
#endif
if (rv < (int)size)
SocketEngine::ChangeEventMask(sock, FD_WRITE_WILL_BLOCK);
return rv;
}
示例2: VectorPush
static ssize_t VectorPush(gnutls_transport_ptr_t transportptr, const giovec_t* iov, int iovcnt)
{
StreamSocket* sock = reinterpret_cast<StreamSocket*>(transportptr);
#ifdef _WIN32
GnuTLSIOHook* session = static_cast<GnuTLSIOHook*>(sock->GetIOHook());
#endif
if (sock->GetEventMask() & FD_WRITE_WILL_BLOCK)
{
#ifdef _WIN32
gnutls_transport_set_errno(session->sess, EAGAIN);
#else
errno = EAGAIN;
#endif
return -1;
}
// Cast the giovec_t to iovec not to IOVector so the correct function is called on Windows
int ret = SocketEngine::WriteV(sock, reinterpret_cast<const iovec*>(iov), iovcnt);
#ifdef _WIN32
// See the function above for more info about the usage of gnutls_transport_set_errno() on Windows
if (ret < 0)
gnutls_transport_set_errno(session->sess, SocketEngine::IgnoreError() ? EAGAIN : errno);
#endif
int size = 0;
for (int i = 0; i < iovcnt; i++)
size += iov[i].iov_len;
if (ret < size)
SocketEngine::ChangeEventMask(sock, FD_WRITE_WILL_BLOCK);
return ret;
}