/*! Performs a POST request to the CoAP server specified in the given \a request and \a data. * Returns a \l{CoapReply} to match the response with the request. */ CoapReply *CoapNetworkAccessManager::post(const CoapRequest &request, const QByteArray &data) { CoapReply *reply = new CoapReply(request, this); reply->setRequestMethod(CoapPdu::Post); reply->setRequestPayload(data); connect(reply, &CoapReply::timeout, this, &CoapNetworkAccessManager::onReplyTimeout); connect(reply, &CoapReply::finished, this, &CoapNetworkAccessManager::onReplyFinished); lookupHost(reply); return reply; }
/*! Enables notifications (observing) on the CoAP server for the resource specified in the * given \a request. * Returns a \l{CoapReply} to match the response with the request. */ CoapReply *CoapNetworkAccessManager::enableResourceNotifications(const CoapRequest &request) { CoapReply *reply = new CoapReply(request, this); reply->setRequestMethod(CoapPdu::Get); reply->setObservation(true); reply->setObservationEnable(true); connect(reply, &CoapReply::timeout, this, &CoapNetworkAccessManager::onReplyTimeout); connect(reply, &CoapReply::finished, this, &CoapNetworkAccessManager::onReplyFinished); lookupHost(reply); return reply; }
int main(int argc, char **argv) { struct hostent *hp; long addr; int c; if (argc != 3) { fprintf(stderr, "usage: %s i.p.addres\n", argv[0]); exit(1); } while (--argc > 0 && (*++argv)[1] == '-') while (c = *++argv[1]) (strcmp(c, "i") == 0) ? lookupIP(*argv[2]) : (strcmp(c, "h") == 0) ? lookupHost(*argv[2]) : usage(); }
bool SocketClient::connectTcp(const String& host, uint16_t port, int maxTime) { sockaddr_in addr; if (!lookupHost(host, port, addr)) return false; mMode = Tcp; bool ok = false; if (connectInternal(mFd, AF_INET, reinterpret_cast<sockaddr*>(&addr), sizeof(sockaddr_in), maxTime)) { ok = true; unsigned int fdflags = EventLoop::Read; if (!mBuffers.empty()) fdflags |= EventLoop::Write; EventLoop::instance()->addFileDescriptor(mFd, fdflags, dataCallback, this); mConnected(this); } return ok; }
bool SocketClient::writeTo(const String& host, uint16_t port, const String& data) { sockaddr_in addr; if (!lookupHost(host, port, addr)) return false; if (mFd == -1) { if (!setupUdp(mFd)) return false; mMode = Udp; } if (pthread_equal(pthread_self(), EventLoop::instance()->thread())) { if (mBuffers.empty()) EventLoop::instance()->addFileDescriptor(mFd, EventLoop::Read | EventLoop::Write, dataCallback, this); mBuffers.push_back(std::make_pair(addr, data)); return writeMore(); } else { EventLoop::instance()->postEvent(this, new DelayedWriteEvent(addr, data)); return true; } }
Jumpropes::LookupObject *Jumpropes::LookupBase::getNonValidHostResponseObject() { return lookupHost( &sNonValidHostName ); }
bool Jumpropes::LookupBase::equalsNonValidHostResponse( const LookupObject *obj ) { LookupObject *nonValid = lookupHost( &sNonValidHostName ); return obj->firstAddressEqualsOneOf( nonValid, true ); }