void HttpAssetTransfer::SendHttpGetAssetRequest(const std::string &resource_uri) { if (http_session_.connected()) { http_session_.abort(); http_session_.detachSocket(); } received_count_ = 0; Poco::URI uri(resource_uri); std::string path(uri.getPathAndQuery()); if (path.empty()) path = "/"; http_session_.setHost(uri.getHost()); http_session_.setPort(uri.getPort()); Poco::Timespan time_out(HTTP_TIMEOUT_MS*1000); http_session_.setTimeout(time_out); Poco::Net::HTTPRequest request; request.setMethod(Poco::Net::HTTPRequest::HTTP_GET); request.setURI(path); request.setVersion(Poco::Net::HTTPMessage::HTTP_1_1); try { http_session_.sendRequest(request); std::istream &s = http_session_.receiveResponse(http_response_); Poco::Net::HTTPResponse::HTTPStatus status = http_response_.getStatus(); switch (status) { case Poco::Net::HTTPResponse::HTTP_OK: response_stream_ = &s; response_size_ = http_response_.getContentLength(); break; default: std::string reason = http_response_.getReasonForStatus(status); std::stringstream error; error << "Http GET failed for: "; error << resource_uri << std::endl; error << "Reason: " << reason; AssetModule::LogError(error.str()); failed_ = true; return; } } catch (Poco::Exception e) { std::stringstream error; error << "Http GET failed for: "; error << resource_uri << std::endl; error << "Reason: " << e.displayText(); AssetModule::LogError(error.str()); failed_ = true; return; } }
// //////////////////////////////////////////////////////////////////////////// bool ServerX::Accept(SocketX &client_socket, unsigned int max_wait_usecs) { MLB::Utility::TimeVal time_out( max_wait_usecs / 1000000, max_wait_usecs % 1000000); if (socket_.SelectRead(&time_out)) return(AcceptInternal(client_socket)); return(false); }
bool Echosounder::getDistance(base::samples::RigidBodyState &state, int timeout) { iodrivers_base::Timeout time_out(timeout); while(!time_out.elapsed()) { size_t size = iodrivers_base::Driver::readPacket(buffer,50,time_out.timeLeft()); if(size>0){ int depth = 0; if(sscanf((const char*)&buffer[0],"%dmm",&depth) == 1) { state.position[2] = 0.001*depth; //We want Si units not mm state.time = base::Time::now(); state.cov_position(2,2) = 0.2; LOG_DEBUG_S <<"decoding EchoSounder: got depth:" << state.position[2]; return true; } else throw std::runtime_error("Cannot decode EchoSounder. Depth was not find in the package"); } } return false; }
void AVPlayer::decode_proc() { while (bRun) { AVPacket packet; av_init_packet(&packet); std::chrono::milliseconds time_out(10); /* 영상 내 프레임을 읽음 */ while (av_read_frame(pFormatCtx, &packet) >= 0) { // int queue_size = vDecoder.video_queue.size(); // if ( queue_size >= vDecoder.max_queue_size) // { // Sleep(10); // continue; // } int stream_index = packet.stream_index; if (stream_index == video_stream_index) { /* process audio packet */ vDecoder.video_queue.push(packet, time_out); } else if (stream_index == audio_stream_index) { /* process video packet */ aDecoder.audio_decode(&packet); } else { av_free_packet(&packet); } } stop_video(); } }
void SeaNet::writeHeadCommand(HeadCommand &head_config, int timeout) { if (has_pending_data) throw std::runtime_error("requestData() called and the corresponding receiveData() has not been called"); iodrivers_base::Timeout time_out(timeout); std::vector<uint8_t> packet = SeaNetPacket::createPaket(device_type, mtHeadCommand, (uint8_t*)&head_config, sizeof(head_config)); LOG_DEBUG_S <<"Sent mtHeadCommand packet" ; writePacket(&packet[0],packet.size(),time_out.timeLeft()); //wait for an alive packet to check if the sonar is configured AliveData alive_data; bool received_alive = false; while(!alive_data.ready && alive_data.no_config && !alive_data.config_send) { try { waitForPacket(mtAlive,time_out.timeLeft()); } catch(std::runtime_error e) { if(received_alive) throw std::runtime_error("Configure failed: Configuration was not accepted by the device."); else throw std::runtime_error("Configure failed: Device is not responding. Timeout too small?"); } received_alive = true; sea_net_packet.decodeAliveData(alive_data); } }
int main(int argc, char *argv []) { TimeZoneAbbrevTable *tzabbr; TimestampTz tsz, eol; Timestamp ts; TimeTzADT *timetz; Interval *i; DateADT d; TimeADT time; char *s; pg_timezone_initialize(); if (!(tzabbr = load_tzoffsets("Default"))) warnx("failed to load Default"); else InstallTimeZoneAbbrevs(tzabbr); warnx("test..."); session_timezone = pg_tzset("Europe/Amsterdam"); tsz = timestamptz_in("2012/1/1 00:20:01+05"); s = timestamptz_out(tsz); warnx("timestamptz: %s", s); ts = timestamp_in("2012/12/12 12:12:12"); s = timestamp_out(ts); warnx("timestamp: %s", s); i = interval_in("10h5m"); s = interval_out(i); warnx("interval: %s", s); i = interval_in("1000000 hours"); s = interval_out(interval_justify_interval(i)); warnx("lifetime: %s", s); d = date_in("1999/9/9"); s = date_out(d); warnx("date: %s", s); time = time_in("10:20"); s = time_out(time); warnx("time: %s", s); timetz = timetz_in("10:20"); s = timetz_out(timetz); warnx("timetz: %s", s); tsz = GetCurrentTimestamp(); s = timestamptz_out(tsz); warnx("timestamptz: %s (now)", s); eol = timestamptz_pl_interval(tsz, interval_justify_interval(i)); s = timestamptz_out(eol); warnx("eol: %s", s); session_timezone = pg_tzset("Canada/Mountain"); s = timestamptz_out(tsz); warnx("timestamptz in canada: %s", s); return EX_OK; }
void SeaNet::waitForPacket(PacketType type,int timeout) { LOG_DEBUG_S << "wait for packet type: "<<type << " timeout " << timeout ; iodrivers_base::Timeout time_out(timeout); while(type != readPacket(time_out.timeLeft())); }
void HttpAssetTransfer::SendHttpPostAssetRequest(const std::string &host, const std::string &json_data) { std::string ASSET_UPLOADING_CONTENT_TYPE = "application/json"; int content_length = json_data.length(); std::istringstream stream(json_data); int send_count = 0; //\todo make member var Poco::URI uri(host); std::string path(uri.getPathAndQuery()); if (path.empty()) path = "/"; http_session_.setHost(uri.getHost()); http_session_.setPort(uri.getPort()); Poco::Timespan time_out(HTTP_TIMEOUT_MS*1000); Poco::Net::HTTPRequest request; request.setMethod(Poco::Net::HTTPRequest::HTTP_POST); std::string t = uri.toString(); request.setURI(uri.getPath()); request.setVersion(Poco::Net::HTTPMessage::HTTP_1_1); request.setContentType(ASSET_UPLOADING_CONTENT_TYPE); request.setContentLength(content_length); request.setKeepAlive(false); try { std::ostream &request_body = http_session_.sendRequest(request); request_body.write(json_data.c_str(), json_data.length()); std::istream &s = http_session_.receiveResponse(http_response_); Poco::Net::HTTPResponse::HTTPStatus status = http_response_.getStatus(); switch (status) { case Poco::Net::HTTPResponse::HTTP_OK: response_stream_ = &s; response_size_ = http_response_.getContentLength(); break; default: std::string reason = http_response_.getReasonForStatus(status); std::stringstream error; error << "Http POST failed for: "; error << host << std::endl; error << "Reason: " << reason; AssetModule::LogError(error.str()); failed_ = true; return; } } catch (Poco::Net::MessageException &e) { std::string u = request.getURI(); std::string m = request.getMethod(); std::string error = e.message(); } catch (Poco::Exception &e) { std::stringstream error; error << "Http POST failed for: "; error << host << std::endl; error << "Reason: " << e.displayText(); AssetModule::LogError(error.str()); failed_ = true; return; } }
bool CPHCallOnStepCondition::obsolete() const { return time_out(); }
bool CPHCallOnStepCondition::is_true() { return time_out(); }
void Timer_New::timeout() { emit time_out(device_port); timer.stop(); }