本文整理汇总了C++中UsageEnvironment::getErrno方法的典型用法代码示例。如果您正苦于以下问题:C++ UsageEnvironment::getErrno方法的具体用法?C++ UsageEnvironment::getErrno怎么用?C++ UsageEnvironment::getErrno使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UsageEnvironment
的用法示例。
在下文中一共展示了UsageEnvironment::getErrno方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readSocket
int readSocket(UsageEnvironment& env,
int socket, unsigned char* buffer, unsigned bufferSize,
struct sockaddr_in& fromAddress,
struct timeval* timeout) {
int bytesRead = -1;
do {
int result = blockUntilReadable(env, socket, timeout);
if (timeout != NULL && result == 0) {
bytesRead = 0;
break;
} else if (result <= 0) {
break;
}
SOCKLEN_T addressSize = sizeof fromAddress;
bytesRead = recvfrom(socket, (char*)buffer, bufferSize, 0,
(struct sockaddr*)&fromAddress,
&addressSize);
if (bytesRead < 0) {
//##### HACK to work around bugs in Linux and Windows:
int err = env.getErrno();
if (err == 111 /*ECONNREFUSED (Linux)*/
#if defined(__WIN32__) || defined(_WIN32)
// What a piece of crap Windows is. Sometimes
// recvfrom() returns -1, but with an 'errno' of 0.
// This appears not to be a real error; just treat
// it as if it were a read of zero bytes, and hope
// we don't have to do anything else to 'reset'
// this alleged error:
|| err == 0
#else
|| err == EAGAIN
#endif
|| err == 113 /*EHOSTUNREACH (Linux)*/) {
//Why does Linux return this for datagram sock?
fromAddress.sin_addr.s_addr = 0;
return 0;
}
//##### END HACK
socketErr(env, "recvfrom() error: ");
break;
}
} while (0);
return bytesRead;
}
示例2: socketJoinGroup
Boolean socketJoinGroup(UsageEnvironment& env, int socket,
netAddressBits groupAddress){
if (!IsMulticastAddress(groupAddress)) return True; // ignore this case
struct ip_mreq imr;
imr.imr_multiaddr.s_addr = groupAddress;
imr.imr_interface.s_addr = ReceivingInterfaceAddr;
if (setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(const char*)&imr, sizeof (struct ip_mreq)) < 0) {
#if defined(__WIN32__) || defined(_WIN32)
if (env.getErrno() != 0) {
// That piece-of-shit toy operating system (Windows) sometimes lies
// about setsockopt() failing!
#endif
socketErr(env, "setsockopt(IP_ADD_MEMBERSHIP) error: ");
return False;
#if defined(__WIN32__) || defined(_WIN32)
}
#endif
}
return True;
}
示例3: printErr
static void printErr(UsageEnvironment& env, char const* str = NULL) {
if (str != NULL) err(env) << str;
env << ": " << strerror(env.getErrno()) << "\n";
}