本文整理汇总了C++中TimeValue::timeval方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeValue::timeval方法的具体用法?C++ TimeValue::timeval怎么用?C++ TimeValue::timeval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeValue
的用法示例。
在下文中一共展示了TimeValue::timeval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: poll_out
// poll for writing
int Sock::poll_out(TimeValue &timeout)
{
#ifndef _WIN32
struct pollfd pollset[1];
pollset[0].fd = sockfd;
pollset[0].events = POLLOUT|POLLERR;
pollset[0].revents = 0;
int result = ::poll(pollset, 1, timeout.msec());
if (result > 0)
return pollset[0].revents;
else
return result;
#else
fd_set fds_write, fds_err;
FD_ZERO(&fds_write);
FD_ZERO(&fds_err);
FD_SET(sockfd, &fds_write);
FD_SET(sockfd, &fds_err);
int result = ::select(0, NULL, &fds_write, &fds_err, timeout.timeval());
if (result <= 0)
return result;
unsigned revents = 0;
if (FD_ISSET(sockfd, &fds_write)) revents |= POLLOUT;
if (FD_ISSET(sockfd, &fds_err)) revents |= POLLERR;
return revents;
#endif
}
示例2: if
int SockConnector::connect(SockStream &stream, InetAddr &addr, TimeValue &tv)
{
int rv = 0;
// non-block socket
stream.set_nonblocking();
#ifdef _WIN32
// connect
rv = ::connect(stream.get_handle(), (const struct sockaddr *) addr.get_addr(), (socklen_t)addr.get_addr_size());
if (rv != -1) {
rv = 0;
}
else {
if (WSAGetLastError() == WSAEWOULDBLOCK)
{
//printf("connect InProgress [%d]\n", sock);
fd_set rset;
fd_set wset;
FD_ZERO(&rset);
FD_ZERO(&wset);
FD_SET(stream.get_handle(), &rset);
FD_SET(stream.get_handle(), &wset);
rv = ::select(0, &rset, &wset, NULL, (struct timeval*)tv.timeval());
if (rv == 0) {
perror("connect timeout");
rv = -1;
}
else if (FD_ISSET(stream.get_handle(), &rset) || FD_ISSET(stream.get_handle(), &wset)) {
int error = 0;
socklen_t len = sizeof(error);
if (getsockopt(stream.get_handle(), SOL_SOCKET, SO_ERROR, (char *)&error, &len) == 0) {
// select error
if (error == 0) {
rv = 0;
}
else {
closesocket(stream.get_handle());
perror("connect");
rv = -1;
}
}
}
else {
perror("connect");
rv = -1;
}
}
else {
perror("connect");
rv = -1;
}
}
#endif
// restore file status flags
stream.set_blocking();
return rv;
}