/** * network_uncork(fd): * Set the TCP_NODELAY socket option, and clear TCP_CORK or TCP_NOPUSH if * either is defined. */ int network_uncork(int fd) { /* Clear TCP_CORK or TCP_NOPUSH as appropriate. */ #ifdef TCP_CORK setopt(fd, TCP_CORK, 0, err0); #else #ifdef TCP_NOPUSH #ifndef BROKEN_TCP_NOPUSH setopt(fd, TCP_NOPUSH, 0, err0); #endif #endif #endif /* Set TCP_NODELAY. */ /* * For compatibility with Linux 2.4, this must be done after we * clear TCP_CORK; otherwise it will throw an EINVAL back at us. */ setopt(fd, TCP_NODELAY, 1, err0); /* Success! */ return (0); err0: /* Failure! */ return (-1); }
static void nfslib_set_sockbuf(int fd) { int curval, val; val = NFSD_TCP_BUFSZ; curval = get_opt(fd, SOL_SOCKET, SO_SNDBUF); syslog(LOG_DEBUG, "Current SO_SNDBUF value is %d", curval); if ((curval != -1) && (curval < val)) { syslog(LOG_DEBUG, "Set SO_SNDBUF option to %d", val); if (setopt(fd, SOL_SOCKET, SO_SNDBUF, val) < 0) { syslog(LOG_ERR, "couldn't set SO_SNDBUF to %d - t_errno = %d", val, t_errno); syslog(LOG_ERR, "Check and increase system-wide tcp_max_buf"); } } curval = get_opt(fd, SOL_SOCKET, SO_RCVBUF); syslog(LOG_DEBUG, "Current SO_RCVBUF value is %d", curval); if ((curval != -1) && (curval < val)) { syslog(LOG_DEBUG, "Set SO_RCVBUF option to %d", val); if (setopt(fd, SOL_SOCKET, SO_RCVBUF, val) < 0) { syslog(LOG_ERR, "couldn't set SO_RCVBUF to %d - t_errno = %d", val, t_errno); syslog(LOG_ERR, "Check and increase system-wide tcp_max_buf"); } } }
/** * network_cork(fd): * Clear the TCP_NODELAY socket option, and set TCP_CORK or TCP_NOPUSH if * either is defined. */ int network_cork(int fd) { /* Clear TCP_NODELAY. */ setopt(fd, TCP_NODELAY, 0, err0); /* Set TCP_CORK or TCP_NOPUSH as appropriate. */ #ifdef TCP_CORK setopt(fd, TCP_CORK, 1, err0); #else #ifdef TCP_NOPUSH #ifndef BROKEN_TCP_NOPUSH setopt(fd, TCP_NOPUSH, 1, err0); #endif #endif #endif /* Success! */ return (0); err0: /* Failure! */ return (-1); }
void loglikdistrib(Int_t ntrials = 10000, Bool_t print = kFALSE) { // compute distribution of log likelihood value TH1D * hmc = gStack[gPadNr][gOrder[gPadNr][0]]; TH1D * hdata = gStack[gPadNr][gMaxProcess-1]; Int_t nbins = hmc->GetNbinsX(); Double_t loglik = loglikelihood(hmc, hdata, 1, nbins); TH1D * htest = new TH1D(*hdata); TH1D * lldistrib = new TH1D("lldistrib", "log(Likelihood) distribution", 1000, loglik-200, loglik+200); setopt(lldistrib); for (Int_t n = 0; n < ntrials; n++) { // generate poisson around theorie for (Int_t i = 1; i <= nbins; i++) { htest->SetBinContent(i, gRandom->Poisson(hmc->GetBinContent(i))); } lldistrib->Fill(loglikelihood(hmc, htest, 1, nbins)); } TCanvas * llcanvas = new TCanvas("llcanvas", "Log(Likelihood) distribution", 40, 40, 800, 600); setopt(llcanvas); lldistrib->SetFillColor(kYellow); lldistrib->Draw(); lldistrib->GetYaxis()->SetTitle("Anzahl Ereignisse"); lldistrib->GetXaxis()->SetTitle("-ln L"); // autozoom Int_t lowbin = 1; while (lldistrib->GetBinContent(lowbin) == 0) lowbin++; Int_t highbin = lldistrib->GetNbinsX(); while (lldistrib->GetBinContent(highbin) == 0) highbin--; lldistrib->SetAxisRange(lldistrib->GetBinLowEdge(lowbin), lldistrib->GetBinLowEdge(highbin)); TH1D * hworse = (TH1D *) lldistrib->Clone(); for (Int_t nbin = 1; nbin < 501; nbin++) { hworse->SetBinContent(nbin, 0); } hworse->SetFillColor(95); hworse->Draw("same"); Double_t pvalue = lldistrib->Integral(501,1000) / lldistrib->Integral(); TLatex * tex = new TLatex(0.18, 0.96, Form("-ln L_{obs} = %5.2f", loglik)); tex->SetNDC(); tex->SetTextAlign(13); tex->Draw(); tex = new TLatex(0.18, 0.86, Form("CL_{obs} = %.3f", pvalue)); tex->SetNDC(); tex->SetTextAlign(13); tex->Draw(); TLine * l = new TLine(loglik, 0, loglik, lldistrib->GetMaximum()); l->SetLineWidth(3); l->SetLineColor(kBlue); l->Draw(); llcanvas->Modified(); llcanvas->Update(); if (print) llcanvas->Print("lldistrib.pdf"); cd(gPadNr+1); }
void calculate_b_efficiency() { TH2D * h2_btag_num_b = 0; plot2("btag_num_b"); for (int i = 0; i < gMaxProcess; i++) { if (strstr(gProcess[i].fname, "ttjets") != 0) { h2_btag_num_b = new TH2D(*gHisto2[i]); } } TH2D * h2_btag_denom_b = 0; plot2("btag_denom_b"); for (int i = 0; i < gMaxProcess; i++) { if (strstr(gProcess[i].fname, "ttjets") != 0) { h2_btag_denom_b = new TH2D(*gHisto2[i]); } } TH2D * h2_b_eff = new TH2D(*h2_btag_num_b); h2_b_eff->Divide(h2_btag_num_b, h2_btag_denom_b, 1., 1., "B"); new TCanvas; //h2_b_eff->GetXaxis()->SetRangeUser(5,800); //h2_b_eff->GetYaxis()->SetRangeUser(-2.4,2.4); h2_b_eff->Draw(); TFile * f = new TFile("btag_eff_map.root", "UPDATE"); h2_b_eff->Smooth(); h2_b_eff->Write(); f->Close(); INFO("Written efficiency map for b-quarks to btag_eff_map.root"); TH1D * h1_btag_num_b = h2_btag_num_b->ProjectionX(); TH1D * h1_btag_denom_b = h2_btag_denom_b->ProjectionX(); TH1D * h1_b_eff = new TH1D(*h1_btag_num_b); h1_b_eff->Divide(h1_btag_num_b, h1_btag_denom_b, 1., 1., "B"); TCanvas * b_proj = new TCanvas("b_proj", "b_proj", 800,600); b_proj->cd(); setopt(b_proj); setopt(h1_b_eff); h1_b_eff->SetMarkerStyle(8); h1_b_eff->SetMarkerSize(.7); h1_b_eff->SetTitle(""); h1_b_eff->GetYaxis()->SetTitle("b-tagging efficiency"); h1_b_eff->GetXaxis()->SetTitle("transverse momentum of jets [GeV]"); h1_b_eff->GetXaxis()->CenterTitle(); h1_b_eff->GetYaxis()->SetTitleFont(62); h1_b_eff->GetYaxis()->SetTitleSize(0.04); h1_b_eff->GetYaxis()->SetLabelFont(62); h1_b_eff->GetYaxis()->SetLabelSize(0.04); h1_b_eff->GetXaxis()->SetTitleFont(62); h1_b_eff->GetXaxis()->SetTitleSize(0.04); h1_b_eff->GetXaxis()->SetLabelFont(62); h1_b_eff->GetXaxis()->SetLabelSize(0.04); h1_b_eff->Draw(); lumi(); drawperiod(); }
int main(int argc, char* argv[]) { std::vector<std::string> args(argv, argv+argc); std::string url; size_t iterations = 1000; try { url = args.at(1); if (args.size() > 2) iterations = atoi(args.at(2).c_str()); } catch (std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; std::cerr << "usage: " << args.at(0) << " url iterations" << std::endl; return 1; } curl_init(); CURL* curl = curl_easy_init(); if (!curl) { logError("curl_easy_init"); return 1; } setopt(curl, CURLOPT_URL, url.c_str()); setopt(curl, CURLOPT_TIMEOUT, 5L); setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L); setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); setopt(curl, CURLOPT_HEADER, 1L); setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); char send_data[] = "words, words, words"; for (size_t i = 0; i < iterations; i++) { ReadState read_state(send_data, strlen(send_data)); setopt(curl, CURLOPT_POST, 1L); setopt(curl, CURLOPT_READFUNCTION, read_callback); setopt(curl, CURLOPT_READDATA, &read_state); setopt(curl, CURLOPT_POSTFIELDSIZE, read_state.remains); bool sent = false; for (size_t i = 0; i < 3; i++) { if (perform(curl)) { std::cout << "^"; sent = true; break; } std::cout << "."; } if (!sent) { std::cout << "!"; } } curl_easy_cleanup(curl); curl_cleanup(); return 0; }
int main(int argc, char **argv) { space(0,0,4096,4096); init(&xd); init(&yd); xd.xsize = yd.xsize = 1.; xx = (struct val *)malloc((unsigned)sizeof(struct val)); labsarr = malloc(1); labsarr[labsiz++] = 0; setopt(argc,argv); if(erasf) erase(); readin(); transpose(); scale(&xd,(struct val *)&xx->xv); scale(&yd,(struct val *)&xx->yv); axes(); title(); plot(); move(1,1); closevt(); return(0); }
int main(int argc, char **argv) { // save lines inputed in a pointer array int lines, revert, fold, directory; fold = directory = 0; revert = 1; // Use dynamic allocation memory: Umm... maybe in the next time. char alloc[ALLOCSIZE]; char *ptarr[MAXLINES]; // Check argument while (--argc > 0 && (*++argv)[0] == '-') { char *p; p = argv[0]; if (!setopt(p,&directory, &revert, &fold)) { youneedhelp(); return EXIT_FAILURE; } } while ((lines = readlines(ptarr, MAXLINES, alloc)) > 0) { // any pointer can be cast to void * and back again without loss of information. int (*comp)(void *, void *, int); // Is it too long :( comp = (int (*)(void *, void *, int))(directory ? strdfcmp : strfcmp); // sorting use quick sort algorithm. myqsort((void**)ptarr, 0, lines-1, comp, fold, revert); writelines(ptarr,lines); } return EXIT_SUCCESS; }
int new_socket(int port) { int cs; int fd; struct protoent *pe; struct sockaddr_in sin; pe = getprotobyname("TCP"); if ((fd = socket(AF_INET, SOCK_STREAM, pe->p_proto)) == -1) return (-1); sin.sin_family = AF_INET; sin.sin_port = htons(port); sin.sin_addr.s_addr = INADDR_ANY; setopt(fd); if (bind(fd, (const struct sockaddr*)&sin, sizeof(sin)) == -1) { close(fd); return (-1); } if ((cs = listen(fd, 1)) == -1) { close(fd); return (-1); } g_dfd = fd; return (0); }
int sockbuf::recvbufsz (int sz) const { int old=0; getopt (so_rcvbuf, &old, sizeof (old)); setopt (so_rcvbuf, &sz, sizeof (sz)); return old; }
U32 LLCurl::Easy::report(CURLcode code) { U32 responseCode = 0; std::string responseReason; if (code == CURLE_OK) { check_curl_code(curl_easy_getinfo(mCurlEasyHandle, CURLINFO_RESPONSE_CODE, &responseCode)); //*TODO: get reason from first line of mHeaderOutput } else { responseCode = 499; responseReason = strerror(code) + " : " + mErrorBuffer; setopt(CURLOPT_FRESH_CONNECT, TRUE); } if (mResponder) { mResponder->completedRaw(responseCode, responseReason, mChannels, mOutput); mResponder = NULL; } resetState(); return responseCode; }
sockbuf::socklinger sockbuf::linger (sockbuf::socklinger opt) const { socklinger old (0, 0); getopt (so_linger, &old, sizeof (old)); setopt (so_linger, &opt, sizeof (opt)); return old; }
bool sockbuf::debug (bool set) const { int old=0; int opt = set; getopt (so_debug, &old, sizeof (old)); setopt (so_debug, &opt, sizeof (opt)); return old!=0; }
bool sockbuf::reuseaddr (bool set) const { int old=0; int opt = set; getopt (so_reuseaddr, &old, sizeof (old)); setopt (so_reuseaddr, &opt, sizeof (opt)); return old!=0; }
bool sockbuf::keepalive (bool set) const { int old=0; int opt = set; getopt (so_keepalive, &old, sizeof (old)); setopt (so_keepalive, &opt, sizeof (opt)); return old!=0; }
bool sockbuf::dontroute (bool set) const { int old = 0; int opt = set; getopt (so_dontroute, &old, sizeof (old)); setopt (so_dontroute, &opt, sizeof (opt)); return old!=0; }
bool sockbuf::broadcast (bool set) const { int old = 0; int opt = set; getopt (so_broadcast, &old, sizeof (old)); setopt (so_broadcast, &opt, sizeof (opt)); return old!=0; }
bool sockbuf::oobinline (bool set) const { int old = 0; int opt = set; getopt (so_oobinline, &old, sizeof (old)); setopt (so_oobinline, &opt, sizeof (opt)); return old!=0; }
bool JPWiFly::setDHCP(const uint8_t mode) { char buf[2]; if (mode > 9) return false; buf[0] = '0' + mode; buf[1] = 0; return setopt(PSTR("set ip dhcp"), buf); }
bool sinsp_curl::get_data(std::ostream& os) { CURLcode res = CURLE_OK; check_error(curl_easy_setopt(m_curl, CURLOPT_URL, m_uri.to_string().c_str())); check_error(curl_easy_setopt(m_curl, CURLOPT_HEADERDATA, m_redirect)); check_error(curl_easy_setopt(m_curl, CURLOPT_HEADERFUNCTION, header_callback)); check_error(curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, static_cast<int>(m_timeout_ms / 1000))); check_error(curl_easy_setopt(m_curl, CURLOPT_TIMEOUT_MS, m_timeout_ms)); check_error(curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1)); //Prevent "longjmp causes uninitialized stack frame" bug check_error(curl_easy_setopt(m_curl, CURLOPT_ACCEPT_ENCODING, "deflate")); check_error(curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, &sinsp_curl::write_data)); check_error(curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &os)); check_error(curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, &read_data)); check_error(curl_easy_setopt(m_curl, CURLOPT_READDATA, &m_body)); if(m_headers.ptr() != NULL) { setopt(CURLOPT_HTTPHEADER, m_headers.ptr()); } res = curl_easy_perform(m_curl); if(res != CURLE_OK) { os << curl_easy_strerror(res) << std::flush; } else { // HTTP errors are not returned by curl API // error will be in the response stream check_error(curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &m_response_code)); if(m_response_code >= 400) { g_logger.log("CURL HTTP error while accessing [" + m_uri.to_string(false) + "]: " + std::to_string(m_response_code) + " (" + http_reason::get(m_response_code) + ')', sinsp_logger::SEV_ERROR); return false; } else if(is_redirect(m_response_code)) { g_logger.log("HTTP redirect (" + std::to_string(m_response_code) + ')', sinsp_logger::SEV_DEBUG); if(handle_redirect(m_uri, std::string(m_redirect), os)) { std::ostringstream* pos = dynamic_cast<std::ostringstream*>(&os); if(pos) { pos->str(""); return get_data(*pos); } else { g_logger.log("HTTP redirect received from [" + m_uri.to_string(false) + "] but " "output stream can not be obtained (dynamic cast failed).", sinsp_logger::SEV_ERROR); return false; } } } } return res == CURLE_OK; }
void LLCurl::Easy::prepRequest(const std::string& url, const std::vector<std::string>& headers, ResponderPtr responder, bool post) { resetState(); if (post) setoptString(CURLOPT_ENCODING, ""); // setopt(CURLOPT_VERBOSE, 1); // usefull for debugging setopt(CURLOPT_NOSIGNAL, 1); mOutput.reset(new LLBufferArray); setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback); setopt(CURLOPT_WRITEDATA, (void*)this); setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback); setopt(CURLOPT_READDATA, (void*)this); setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback); setopt(CURLOPT_HEADERDATA, (void*)this); setErrorBuffer(); setCA(); setopt(CURLOPT_SSL_VERIFYPEER, LLCurl::getSSLVerify()); setopt(CURLOPT_SSL_VERIFYHOST, LLCurl::getSSLVerify()? 2 : 0); setopt(CURLOPT_TIMEOUT, CURL_REQUEST_TIMEOUT); setoptString(CURLOPT_URL, url); mResponder = responder; if (!post) { slist_append("Connection: keep-alive"); slist_append("Keep-alive: 300"); // Accept and other headers for (std::vector<std::string>::const_iterator iter = headers.begin(); iter != headers.end(); ++iter) { slist_append((*iter).c_str()); } } }
int main(int argc, char **argv) { FILE *fi; char sobuf[BUFSIZ]; char *cp; int nofile; char *locale; outp = NOSTR; setbuf(stdout, sobuf); setlocale(LC_ALL, ""); locale = setlocale(LC_CTYPE, ""); if (strcmp(locale, "C") == 0) { split = csplit; } else { split = msplit; _wckind_init(); } if (argc < 2) { single: fmt(stdin); oflush(); exit(0); } nofile = 1; while (--argc) { cp = *++argv; if (setopt(cp)) continue; nofile = 0; if ((fi = fopen(cp, "r")) == NULL) { perror(cp); errs++; continue; } fmt(fi); fclose(fi); } if (nofile) goto single; oflush(); fclose(stdout); return (errs); }
void LLCurl::Easy::prepRequest(const std::string& url, ResponderPtr responder, bool post) { resetState(); if (post) setoptString(CURLOPT_ENCODING, ""); // setopt(CURLOPT_VERBOSE, 1); // usefull for debugging setopt(CURLOPT_NOSIGNAL, 1); mOutput.reset(new LLBufferArray); setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback); setopt(CURLOPT_WRITEDATA, (void*)this); setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback); setopt(CURLOPT_READDATA, (void*)this); setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback); setopt(CURLOPT_HEADERDATA, (void*)this); setErrorBuffer(); setCA(); setopt(CURLOPT_SSL_VERIFYPEER, true); setopt(CURLOPT_TIMEOUT, CURL_REQUEST_TIMEOUT); setoptString(CURLOPT_URL, url); mResponder = responder; if (!post) { slist_append("Connection: keep-alive"); slist_append("Keep-alive: 300"); } // *FIX: should have ACCEPT headers }
int make_socket(const int fe_port) { const int socketfd = socket(AF_INET, SOCK_STREAM, 0); if (socketfd < 0) { error("ERROR opening socket"); } else { // printf("new socket %d\n", socketfd); setopt(socketfd); } struct sockaddr_in servaddr; bzero(&servaddr, sizeof(servaddr)); servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(fe_port); servaddr.sin_family = AF_INET; if (bind(socketfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) error("ERROR on binding"); return socketfd; }
std::pair<http::Status, std::string> HttpClient::del(const std::string& path, const std::string& query) { std::pair<http::Status, std::string> r; r.second.reserve(Buffer_Size); setopt(CURLOPT_HEADERFUNCTION, &headerStatusCallback); setopt(CURLOPT_URL, makeUrl(path, query).c_str()); setopt(CURLOPT_WRITEDATA, &r.second); setopt(CURLOPT_HEADERDATA, &r.first); setopt(CURLOPT_HTTPGET, 1l); setopt(CURLOPT_CUSTOMREQUEST, "DELETE"); perform(); return r; }
int get_sendfd(const char* sqlserver_ip, const int sqlserver_port) { const int sendfd = socket(AF_INET, SOCK_STREAM, 0); if (sendfd < 0) { error("ERROR opening socket"); } else if (!sqlserver_ip || *sqlserver_ip == '\0') { error("ERROR on sql server ip"); } else { // printf("new socket on %d, %s %d\n", sendfd, sqlserver_ip, sqlserver_port); setopt(sendfd); } struct sockaddr_in sendaddr; bzero(&sendaddr, sizeof(sendaddr)); sendaddr.sin_family = AF_INET; sendaddr.sin_addr.s_addr = inet_addr(sqlserver_ip); // sendaddr.sin_addr.s_addr = htonl(INADDR_ANY); sendaddr.sin_port = htons(sqlserver_port); if (connect(sendfd, (struct sockaddr *) &sendaddr,sizeof(sendaddr)) < 0) error("ERROR connecting"); else printf("connected to backend sql server from port: %d\n", sqlserver_port); return sendfd; }
int bl_update_main(int argc, char *argv[]) { if (argc != 2) errx(1, "missing firmware filename or command"); if (!strcmp(argv[1], "setopt")) setopt(); int fd = open(argv[1], O_RDONLY); if (fd < 0) err(1, "open %s", argv[1]); struct stat s; if (stat(argv[1], &s) < 0) err(1, "stat %s", argv[1]); /* sanity-check file size */ if (s.st_size > 16384) errx(1, "%s: file too large", argv[1]); uint8_t *buf = malloc(s.st_size); if (buf == NULL) errx(1, "failed to allocate %u bytes for firmware buffer", s.st_size); if (read(fd, buf, s.st_size) != s.st_size) err(1, "firmware read error"); close(fd); uint32_t *hdr = (uint32_t *)buf; if ((hdr[0] < 0x20000000) || /* stack not below RAM */ (hdr[0] > (0x20000000 + (128 * 1024))) || /* stack not above RAM */ (hdr[1] < 0x08000000) || /* entrypoint not below flash */ ((hdr[1] - 0x08000000) > 16384)) { /* entrypoint not outside bootloader */ free(buf); errx(1, "not a bootloader image"); } warnx("image validated, erasing bootloader..."); usleep(10000); /* prevent other tasks from running while we do this */ sched_lock(); /* unlock the control register */ volatile uint32_t *keyr = (volatile uint32_t *)0x40023c04; *keyr = 0x45670123U; *keyr = 0xcdef89abU; volatile uint32_t *sr = (volatile uint32_t *)0x40023c0c; volatile uint32_t *cr = (volatile uint32_t *)0x40023c10; volatile uint8_t *base = (volatile uint8_t *)0x08000000; /* check the control register */ if (*cr & 0x80000000) { warnx("WARNING: flash unlock failed, flash aborted"); goto flash_end; } /* erase the bootloader sector */ *cr = 0x2; *cr = 0x10002; /* wait for the operation to complete */ while (*sr & 0x1000) { } if (*sr & 0xf2) { warnx("WARNING: erase error 0x%02x", *sr); goto flash_end; } /* verify the erase */ for (int i = 0; i < s.st_size; i++) { if (base[i] != 0xff) { warnx("WARNING: erase failed at %d - retry update, DO NOT reboot", i); goto flash_end; } } warnx("flashing..."); /* now program the bootloader - speed is not critical so use x8 mode */ for (int i = 0; i < s.st_size; i++) { /* program a byte */ *cr = 1; base[i] = buf[i]; /* wait for the operation to complete */ while (*sr & 0x1000) { } if (*sr & 0xf2) { warnx("WARNING: program error 0x%02x", *sr); goto flash_end; } } /* re-lock the flash control register */ *cr = 0x80000000; warnx("verifying..."); /* now run a verify pass */ for (int i = 0; i < s.st_size; i++) { if (base[i] != buf[i]) { warnx("WARNING: verify failed at %u - retry update, DO NOT reboot", i); goto flash_end; } } warnx("bootloader update complete"); flash_end: /* unlock the scheduler */ sched_unlock(); free(buf); exit(0); }
void LLCurl::Easy::prepRequest(const std::string& url, const std::vector<std::string>& headers, ResponderPtr responder, S32 time_out, bool post) { resetState(); if (post) setoptString(CURLOPT_ENCODING, ""); //setopt(CURLOPT_VERBOSE, 1); // useful for debugging setopt(CURLOPT_NOSIGNAL, 1); // Set the CURL options for either Socks or HTTP proxy LLProxy::getInstance()->applyProxySettings(this); mOutput.reset(new LLBufferArray); mOutput->setThreaded(true); setopt(CURLOPT_WRITEFUNCTION, (void*)&curlWriteCallback); setopt(CURLOPT_WRITEDATA, (void*)this); setopt(CURLOPT_READFUNCTION, (void*)&curlReadCallback); setopt(CURLOPT_READDATA, (void*)this); setopt(CURLOPT_HEADERFUNCTION, (void*)&curlHeaderCallback); setopt(CURLOPT_HEADERDATA, (void*)this); // Allow up to five redirects if (responder && responder->followRedir()) { setopt(CURLOPT_FOLLOWLOCATION, 1); setopt(CURLOPT_MAXREDIRS, MAX_REDIRECTS); } setErrorBuffer(); setCA(); setopt(CURLOPT_SSL_VERIFYPEER, true); //don't verify host name so urls with scrubbed host names will work (improves DNS performance) setopt(CURLOPT_SSL_VERIFYHOST, 0); setopt(CURLOPT_TIMEOUT, llmax(time_out, CURL_REQUEST_TIMEOUT)); setoptString(CURLOPT_URL, url); mResponder = responder; if (!post) { slist_append("Connection: keep-alive"); slist_append("Keep-alive: 300"); // Accept and other headers for (std::vector<std::string>::const_iterator iter = headers.begin(); iter != headers.end(); ++iter) { slist_append((*iter).c_str()); } } }
void LLCurl::Easy::setErrorBuffer() { setopt(CURLOPT_ERRORBUFFER, &mErrorBuffer); }
void LLCurl::Easy::setHeaders() { setopt(CURLOPT_HTTPHEADER, mHeaders); }