void CoordinatedGraphicsLayer::didChangeImageBacking() { m_shouldSyncImageBacking = true; if (client()) client()->notifyFlushRequired(this); }
bool ResourceHandle::onRequestComplete() { if (!d->m_internetHandle) { // 0 if canceled. deref(); // balances ref in start return false; } if (d->m_bytesRemainingToWrite) { DWORD bytesWritten; InternetWriteFile(d->m_requestHandle, d->m_formData.data() + (d->m_formData.size() - d->m_bytesRemainingToWrite), d->m_bytesRemainingToWrite, &bytesWritten); d->m_bytesRemainingToWrite -= bytesWritten; if (d->m_bytesRemainingToWrite) return true; d->m_formData.clear(); } if (!d->m_sentEndRequest) { HttpEndRequestW(d->m_requestHandle, 0, 0, reinterpret_cast<DWORD_PTR>(this)); d->m_sentEndRequest = true; return true; } static const int bufferSize = 32768; char buffer[bufferSize]; INTERNET_BUFFERSA buffers; buffers.dwStructSize = sizeof(INTERNET_BUFFERSA); buffers.lpvBuffer = buffer; buffers.dwBufferLength = bufferSize; BOOL ok = FALSE; while ((ok = InternetReadFileExA(d->m_requestHandle, &buffers, d->m_loadSynchronously ? 0 : IRF_NO_WAIT, reinterpret_cast<DWORD_PTR>(this))) && buffers.dwBufferLength) { if (!d->m_hasReceivedResponse) { d->m_hasReceivedResponse = true; ResourceResponse response; response.setURL(firstRequest().url()); String httpStatusText = queryHTTPHeader(d->m_requestHandle, HTTP_QUERY_STATUS_TEXT); if (!httpStatusText.isNull()) response.setHTTPStatusText(httpStatusText); String httpStatusCode = queryHTTPHeader(d->m_requestHandle, HTTP_QUERY_STATUS_CODE); if (!httpStatusCode.isNull()) response.setHTTPStatusCode(httpStatusCode.toInt()); String httpContentLength = queryHTTPHeader(d->m_requestHandle, HTTP_QUERY_CONTENT_LENGTH); if (!httpContentLength.isNull()) response.setExpectedContentLength(httpContentLength.toInt()); String httpContentType = queryHTTPHeader(d->m_requestHandle, HTTP_QUERY_CONTENT_TYPE); if (!httpContentType.isNull()) { response.setMimeType(extractMIMETypeFromMediaType(httpContentType)); response.setTextEncodingName(extractCharsetFromMediaType(httpContentType)); } if (ResourceHandleClient* resourceHandleClient = client()) resourceHandleClient->didReceiveResponse(this, response); } // FIXME: https://bugs.webkit.org/show_bug.cgi?id=19793 // -1 means we do not provide any data about transfer size to inspector so it would use // Content-Length headers or content size to show transfer size. if (ResourceHandleClient* resourceHandleClient = client()) resourceHandleClient->didReceiveData(this, buffer, buffers.dwBufferLength, -1); buffers.dwBufferLength = bufferSize; } if (!ok && GetLastError() == ERROR_IO_PENDING) return true; if (ResourceHandleClient* resourceHandleClient = client()) resourceHandleClient->didFinishLoading(this, 0); InternetCloseHandle(d->m_requestHandle); InternetCloseHandle(d->m_connectHandle); deref(); // balances ref in start return false; }
/// \cond bool QXmppRosterManager::handleStanza(const QDomElement &element) { if (element.tagName() != "iq" || !QXmppRosterIq::isRosterIq(element)) return false; // Security check: only server should send this iq // from() should be either empty or bareJid of the user const QString fromJid = element.attribute("from"); if (!fromJid.isEmpty() && QXmppUtils::jidToBareJid(fromJid) != client()->configuration().jidBare()) return false; QXmppRosterIq rosterIq; rosterIq.parse(element); bool isInitial = (d->rosterReqId == rosterIq.id()); switch(rosterIq.type()) { case QXmppIq::Set: { // send result iq QXmppIq returnIq(QXmppIq::Result); returnIq.setId(rosterIq.id()); client()->sendPacket(returnIq); // store updated entries and notify changes const QList<QXmppRosterIq::Item> items = rosterIq.items(); foreach (const QXmppRosterIq::Item &item, items) { const QString bareJid = item.bareJid(); if (item.subscriptionType() == QXmppRosterIq::Item::Remove) { if (d->entries.remove(bareJid)) { // notify the user that the item was removed emit itemRemoved(bareJid); } } else { const bool added = !d->entries.contains(bareJid); d->entries.insert(bareJid, item); if (added) { // notify the user that the item was added emit itemAdded(bareJid); } else { // notify the user that the item changed emit itemChanged(bareJid); } // FIXME: remove legacy signal emit rosterChanged(bareJid); } } } break; case QXmppIq::Result: { const QList<QXmppRosterIq::Item> items = rosterIq.items(); foreach (const QXmppRosterIq::Item &item, items) { const QString bareJid = item.bareJid(); d->entries.insert(bareJid, item); if (!isInitial) emit rosterChanged(bareJid); } if (isInitial) { d->isRosterReceived = true; emit rosterReceived(); } break; } default: break; } return true; }
int main(int argc, char* argv[]) { return client(); }
FrameLoaderClient* LocalFrame::loaderClient() const { return static_cast<FrameLoaderClient*>(client()); }
Client Client::create(ClientConfig config) throw (voltdb::Exception, voltdb::LibEventException) { Client client(new ClientImpl(config)); return client; }
// Alsa handles accessors. int qjackctlAlsaPort::alsaClient (void) const { return (static_cast<qjackctlAlsaClient *> (client()))->alsaClient(); }
void GraphicsLayerTextureMapper::commitLayerChanges() { #if PLATFORM(JS) webkitTrace(); #endif if (m_changeMask == NoChanges) return; if (m_changeMask & ChildrenChange) { Vector<TextureMapperLayer*> textureMapperLayerChildren; toTextureMapperLayerVector(children(), textureMapperLayerChildren); m_layer->setChildren(textureMapperLayerChildren); } if (m_changeMask & MaskLayerChange) m_layer->setMaskLayer(toTextureMapperLayer(maskLayer())); if (m_changeMask & ReplicaLayerChange) m_layer->setReplicaLayer(toTextureMapperLayer(replicaLayer())); if (m_changeMask & PositionChange) m_layer->setPosition(position()); if (m_changeMask & AnchorPointChange) m_layer->setAnchorPoint(anchorPoint()); if (m_changeMask & SizeChange) m_layer->setSize(size()); if (m_changeMask & TransformChange) m_layer->setTransform(transform()); if (m_changeMask & ChildrenTransformChange) m_layer->setChildrenTransform(childrenTransform()); if (m_changeMask & Preserves3DChange) m_layer->setPreserves3D(preserves3D()); if (m_changeMask & ContentsRectChange) m_layer->setContentsRect(contentsRect()); if (m_changeMask & MasksToBoundsChange) m_layer->setMasksToBounds(masksToBounds()); if (m_changeMask & DrawsContentChange) m_layer->setDrawsContent(drawsContent()); if (m_changeMask & ContentsVisibleChange) m_layer->setContentsVisible(contentsAreVisible()); if (m_changeMask & ContentsOpaqueChange) m_layer->setContentsOpaque(contentsOpaque()); if (m_changeMask & BackfaceVisibilityChange) m_layer->setBackfaceVisibility(backfaceVisibility()); if (m_changeMask & OpacityChange) m_layer->setOpacity(opacity()); if (m_changeMask & BackgroundColorChange) m_layer->setSolidColor(solidColor()); #if ENABLE(CSS_FILTERS) if (m_changeMask & FilterChange) m_layer->setFilters(filters()); #endif if (m_changeMask & BackingStoreChange) m_layer->setBackingStore(m_backingStore); if (m_changeMask & DebugVisualsChange) m_layer->setDebugVisuals(isShowingDebugBorder(), debugBorderColor(), debugBorderWidth(), isShowingRepaintCounter()); if (m_changeMask & RepaintCountChange) m_layer->setRepaintCount(repaintCount()); if (m_changeMask & ContentChange) m_layer->setContentsLayer(platformLayer()); if (m_changeMask & AnimationChange) m_layer->setAnimations(m_animations); if (m_changeMask & AnimationStarted) client()->notifyAnimationStarted(this, m_animationStartTime); if (m_changeMask & FixedToViewporChange) m_layer->setFixedToViewport(fixedToViewport()); if (m_changeMask & IsScrollableChange) m_layer->setIsScrollable(isScrollable()); if (m_changeMask & CommittedScrollOffsetChange) m_layer->didCommitScrollOffset(m_committedScrollOffset); m_changeMask = NoChanges; }
virtual ~CollectionBase() { client().dropCollection( ns() ); }
void PopupMenuHaiku::updateFromElement() { client()->setTextFromItem(m_popupClient->selectedIndex()); }
int main(int argc, char *argv[]) { char command[2]; memset(command, 0, 2); rtspClient client(streamUri, servIP, port); while(1){ fprintf(stdout, "please input the command:\n" "-[method option]:\n" "-b setup \n" "-p play \n" "-t teardown \n" "-w move up \n" "-s move down \n" "-a move left \n" "-d move right \n" "-c click \n" "-0~9 input number\n" "-e backspace \n" "-n enter \n" "-q quit \n"); fprintf(stdout, ">"); fscanf(stdin, "%s", command); switch(command[0]){ case 'b': client.Setup(); break; case 'p': client.Play(); break; case 't': client.Teardown(); break; case 'w': client.Play('w'); break; case 's': client.Play('s'); break; case 'a': client.Play('a'); break; case 'd': client.Play('d'); break; case 'c': client.Play('c'); break; case '0': client.Play('0'); break; case '1': client.Play('1'); break; case '2': client.Play('2'); break; case '3': client.Play('3'); break; case '4': client.Play('4'); break; case '5': client.Play('5'); break; case '6': client.Play('6'); break; case '7': client.Play('7'); break; case '8': client.Play('8'); break; case '9': client.Play('9'); break; case 'e': client.Play('e'); break; case 'n': client.Play('n'); break; case 'q': return 0; break; default: fprintf(stdout, "Illegal Input!\n"); break; } } return 0; }
void TestConnection::testConnectSendReceive() { DSTACK("TestConnection::Run"); /* Test some real connections NOTE: This mostly tests the legacy interface. */ u32 proto_id = 0xad26846a; Handler hand_server("server"); Handler hand_client("client"); Address address(0, 0, 0, 0, 30001); Address bind_addr(0, 0, 0, 0, 30001); /* * Try to use the bind_address for servers with no localhost address * For example: FreeBSD jails */ std::string bind_str = g_settings->get("bind_address"); try { bind_addr.Resolve(bind_str.c_str()); if (!bind_addr.isIPv6()) { address = bind_addr; } } catch (ResolveError &e) { } infostream << "** Creating server Connection" << std::endl; con::Connection server(proto_id, 512, 5.0, false, &hand_server); server.Serve(address); infostream << "** Creating client Connection" << std::endl; con::Connection client(proto_id, 512, 5.0, false, &hand_client); UASSERT(hand_server.count == 0); UASSERT(hand_client.count == 0); sleep_ms(50); Address server_address(127, 0, 0, 1, 30001); if (address != Address(0, 0, 0, 0, 30001)) { server_address = bind_addr; } infostream << "** running client.Connect()" << std::endl; client.Connect(server_address); sleep_ms(50); // Client should not have added client yet UASSERT(hand_client.count == 0); try { NetworkPacket pkt; infostream << "** running client.Receive()" << std::endl; client.Receive(&pkt); infostream << "** Client received: peer_id=" << pkt.getPeerId() << ", size=" << pkt.getSize() << std::endl; } catch (con::NoIncomingDataException &e) { } // Client should have added server now UASSERT(hand_client.count == 1); UASSERT(hand_client.last_id == 1); // Server should not have added client yet UASSERT(hand_server.count == 0); sleep_ms(100); try { NetworkPacket pkt; infostream << "** running server.Receive()" << std::endl; server.Receive(&pkt); infostream << "** Server received: peer_id=" << pkt.getPeerId() << ", size=" << pkt.getSize() << std::endl; } catch (con::NoIncomingDataException &e) { // No actual data received, but the client has // probably been connected } // Client should be the same UASSERT(hand_client.count == 1); UASSERT(hand_client.last_id == 1); // Server should have the client UASSERT(hand_server.count == 1); UASSERT(hand_server.last_id == 2); //sleep_ms(50); while (client.Connected() == false) { try { NetworkPacket pkt; infostream << "** running client.Receive()" << std::endl; client.Receive(&pkt); infostream << "** Client received: peer_id=" << pkt.getPeerId() << ", size=" << pkt.getSize() << std::endl; } catch (con::NoIncomingDataException &e) { } sleep_ms(50); } sleep_ms(50); try { NetworkPacket pkt; infostream << "** running server.Receive()" << std::endl; server.Receive(&pkt); infostream << "** Server received: peer_id=" << pkt.getPeerId() << ", size=" << pkt.getSize() << std::endl; } catch (con::NoIncomingDataException &e) { } /* Simple send-receive test */ { NetworkPacket pkt; pkt.putRawPacket((u8*) "Hello World !", 14, 0); Buffer<u8> sentdata = pkt.oldForgePacket(); infostream<<"** running client.Send()"<<std::endl; client.Send(PEER_ID_SERVER, 0, &pkt, true); sleep_ms(50); NetworkPacket recvpacket; infostream << "** running server.Receive()" << std::endl; server.Receive(&recvpacket); infostream << "** Server received: peer_id=" << pkt.getPeerId() << ", size=" << pkt.getSize() << ", data=" << (const char*)pkt.getU8Ptr(0) << std::endl; Buffer<u8> recvdata = pkt.oldForgePacket(); UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0); } u16 peer_id_client = 2; /* Send a large packet */ { const int datasize = 30000; NetworkPacket pkt(0, datasize); for (u16 i=0; i<datasize; i++) { pkt << (u8) i/4; } infostream << "Sending data (size=" << datasize << "):"; for (int i = 0; i < datasize && i < 20; i++) { if (i % 2 == 0) infostream << " "; char buf[10]; snprintf(buf, 10, "%.2X", ((int)((const char *)pkt.getU8Ptr(0))[i]) & 0xff); infostream<<buf; } if (datasize > 20) infostream << "..."; infostream << std::endl; Buffer<u8> sentdata = pkt.oldForgePacket(); server.Send(peer_id_client, 0, &pkt, true); //sleep_ms(3000); Buffer<u8> recvdata; infostream << "** running client.Receive()" << std::endl; u16 peer_id = 132; u16 size = 0; bool received = false; u32 timems0 = porting::getTimeMs(); for (;;) { if (porting::getTimeMs() - timems0 > 5000 || received) break; try { NetworkPacket pkt; client.Receive(&pkt); size = pkt.getSize(); peer_id = pkt.getPeerId(); recvdata = pkt.oldForgePacket(); received = true; } catch (con::NoIncomingDataException &e) { } sleep_ms(10); } UASSERT(received); infostream << "** Client received: peer_id=" << peer_id << ", size=" << size << std::endl; infostream << "Received data (size=" << size << "): "; for (int i = 0; i < size && i < 20; i++) { if (i % 2 == 0) infostream << " "; char buf[10]; snprintf(buf, 10, "%.2X", ((int)(recvdata[i])) & 0xff); infostream << buf; } if (size > 20) infostream << "..."; infostream << std::endl; UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0); UASSERT(peer_id == PEER_ID_SERVER); } // Check peer handlers UASSERT(hand_client.count == 1); UASSERT(hand_client.last_id == 1); UASSERT(hand_server.count == 1); UASSERT(hand_server.last_id == 2); }
void WebLocalFrameImpl::didFail(const ResourceError& error) { if (!client()) return; client()->didFailLoad(this, error); }
void CoordinatedGraphicsLayer::tiledBackingStoreHasPendingTileCreation() { setNeedsVisibleRectAdjustment(); if (client()) client()->notifyFlushRequired(this); }
int _tmain(int argc, _TCHAR* argv[]) { std::array<std::string, 4> ar{ { "The boost::asio::buffer() function provides a convenient way " "to create the buffer classes, where the size of the buffer is " "deduced from the type possible.", "When Boost.Asio is able to deduce the buffer length, then Boost.", "The compiler expects to get an int and not an initializer-list, " "that's the reason for the error.", "The fundamental question becomes how does one know how much memory " "to allocate, if Boost.Asio does not transmit the size." } }; std::string str = "The compiler expects to get an int and not an initializer-list, that's the reason for the error."; /* std::array<int, 10> ar1{ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } }; std::vector<std::thread> threads; printer pr; for (int i = 0; i < 4; i++) { threads.push_back(std::thread([&pr, i, &ar]() { pr.print_msg(ar[i]); std::chrono::milliseconds duration(500); std::this_thread::sleep_for(duration); pr.print_msg(ar[i]); })); } for (std::thread &t : threads) t.join(); */ try { io_service service_server; echo_server server(service_server); getline(std::cin, str); if (str == "1") { std::thread t1([&service_server]() { service_server.run(); }); while (true) { getline(std::cin, str); if (str == "exit") { server.stop_accept(); break; } io_service service_client; echo_client client(service_client, str); std::thread t2([&service_client]() { service_client.run(); }); t2.join(); } t1.join(); } else { ///* std::thread main_thread([&service_server]() { service_server.run(); }); while (true) { getline(std::cin, str); if (str == "exit") { server.stop_accept(); break; } std::vector<std::unique_ptr<io_service>> clients_services; std::vector<std::unique_ptr<echo_client>> clients; std::vector<std::thread> threads; for (int i = 0; i < 4; i++) { clients_services.emplace_back(new io_service()); //echo_client client(*clients_services[i], ar[i]); clients.emplace_back(new echo_client(*clients_services[i], ar[i])); threads.push_back(std::thread([i, &clients_services]() { clients_services[i]->run(); })); } for (auto & t : threads) t.join(); } main_thread.join(); std::cout << "Main thread exit" << std::endl; //*/ } } catch (std::exception &e) { std::cout << e.what() << std::endl; } system("pause"); return 0; }
int main( int argc, char *argv[] ) { // catch process signals signal( SIGINT, term ); signal( SIGTERM, term ); int ret = EXIT_SUCCESS; string filename = ""; string name = "fogboxrecv"; int timeout = 1; int count = 1; system( "mkdir -p /root/rsync/media/USER1/" ); system( "mkdir -p /root/rsync/media/USER2/" ); system( "mkdir -p /root/rsync/media/USER3/" ); system( "mkdir -p /root/rsync/media/USER4/" ); try { // Create a stream to the server using TCP. ibrcommon::tcpclient conn; // connect to the standard local api port conn.open( "127.0.0.1", 4550 ); // enable nodelay option conn.enableNoDelay(); // Initiate a client for synchronous receiving dtn::api::Client client( name, conn ); // export objects for the signal handler _conn = &conn; _client = &client; // Connect to the server. Actually, this function initiate the // stream protocol by starting the thread and sending the contact header. client.connect(); // std::fstream file; // if (!_stdout) // { // std::cout << "Wait for incoming bundle... " << std::endl; // file.open(filename.c_str(), ios::in|ios::out|ios::binary|ios::trunc); // file.exceptions(std::ios::badbit | std::ios::eofbit); // } while( run == true ) { // receive the bundle dtn::api::Bundle b = client.getBundle( timeout ); cout << "recvd a bundle" << endl; // get the reference to the blob ibrcommon::BLOB::Reference ref = b.getData(); struct timeval now; ::gettimeofday( &now, 0 ); fstream tmpfile; tmpfile.open( "/root/rsync/media/tmpfile", ios::in|ios::out|ios::binary|ios::trunc ); tmpfile.exceptions( std::ios::badbit | std::ios::eofbit ); tmpfile << ref.iostream()->rdbuf(); // tmpfile.close(); cout << "wrote to temp file" << endl; tmpfile.seekg ( 0, ios::beg ); cout << "seek to beg" << endl; char c[256]; tmpfile.get( c,256 ); stringstream filename; int counter = 0; while ( c[counter] != '|' ) filename << c[counter++]; cout << "filename is " << filename.str() << endl; fstream actualfile; actualfile.open( filename.str().c_str(), ios::in|ios::out|ios::binary|ios::trunc ); actualfile.exceptions( std::ios::badbit | std::ios::eofbit ); tmpfile.seekg ( 0, ios::beg ); tmpfile.seekg ( counter+3 ); actualfile << tmpfile.rdbuf(); cout << "wrote to real file " << endl; tmpfile.close(); actualfile.close(); // cout << (now.tv_sec - 946684800) << ": " << ref.iostream()->rdbuf() << endl; cout << ( now.tv_sec - 946684800 ) << " : " << c << endl; // cout << (now.tv_sec - 946684800) << " recvd file " << endl; } // Shutdown the client connection. client.close(); // close the tcp connection conn.close(); } catch ( const dtn::api::ConnectionTimeoutException& ) { std::cerr << "Timeout." << std::endl; ret = EXIT_FAILURE; } catch ( const dtn::api::ConnectionAbortedException& ) { std::cerr << "Aborted." << std::endl; ret = EXIT_FAILURE; } catch ( const dtn::api::ConnectionException& ) { } catch ( const std::exception &ex ) { std::cerr << "Error: " << ex.what() << std::endl; ret = EXIT_FAILURE; } return ret; }
int main() { protolayer::server::Client client(80000); client.shutdown(); return 0; }
bool QJubatusClustering::push(const QList<IndexedPoint> &data) { bool ret = false; EXEC_JUBATUS_COMMAND( ret = client()->push(convert(data)); ) return ret;
int main(int argc, const char * argv[]) { char *keystoredir; char *arg_interface = NULL; char *token, *dup; int i; int num_input_interfaces = 0; uint16_t src; struct stat s; struct interface *input_interface; if (argc <= 5) { print_usage(); exit(1); } if (!((strcmp("-s", argv[1]) == 0) || (strcmp("-c", argv[1]) == 0))) { print_usage(); exit(1); } if (strcmp("-src", argv[2]) != 0) { print_usage(); exit(1); } if (strcmp("-d", argv[4]) != 0) { print_usage(); exit(1); } if (strcmp("-i", argv[6]) != 0) { print_usage(); exit(1); } src = (uint16_t) atoi(argv[3]); keystoredir = strdup(argv[5]); // Remove / if the dirname ends with a slash if (keystoredir[strlen(keystoredir)-1] == '/') { keystoredir[strlen(keystoredir)-1] = '\0'; } // Check if the keystore directory exists if (stat(keystoredir, &s) == -1) { fprintf(stderr, "Error: keystore %s does not exist\n", keystoredir); exit(1); } else { if(!S_ISDIR(s.st_mode)) { fprintf(stderr, "Error: keystore %s is not a directory\n", keystoredir); exit(1); } } arg_interface = strdup(argv[7]); /* * Network Interfaces * */ // Count commas to get the upper bound of the number of interfaces for (i=0; i<strlen(arg_interface); i++) { if (arg_interface[i] == ',') num_input_interfaces++; } num_input_interfaces++; // Allocate input interface array input_interface = (struct interface *) malloc(num_input_interfaces * sizeof(struct interface)); // Parse input interfaces num_input_interfaces = 0; dup = strdup(arg_interface); while ((token = strtok(dup, ",")) != NULL) { strcpy(input_interface[num_input_interfaces].interface_name, token); fill_interface_info(&input_interface[num_input_interfaces]); // Interface name is valid if (input_interface[num_input_interfaces].interface_index != -1) { num_input_interfaces++; } dup = NULL; } free(arg_interface); free(token); // Check if the number of interfaces is at least 1 if (num_input_interfaces <= 0) { fprintf(stderr, "Error: no valid network interfaces\n"); exit(1); } // Print listening interfaces information #ifdef _VERBOSE fprintf(stderr, "[NETWORK INTERFACES]\n"); fprintf(stderr, " Number of network interfaces: %d\n", num_input_interfaces); fprintf(stderr, " %-5s %-6s %-19s %-15s\n", "Dev", "DevId", "Interface MAC addr", "Inf IP addr"); for(i=0; i<num_input_interfaces; i++) { fprintf(stderr, "%2d ", i+1); fprintf_interface(stderr, &input_interface[i]); } fprintf(stderr, "\n"); #endif if (strcmp("-s", argv[1]) == 0) { server(src, keystoredir, num_input_interfaces, &input_interface); } else if (strcmp("-c", argv[1]) == 0) { client(src, keystoredir, num_input_interfaces, &input_interface); } return 0; }
int main(int argc, char **argv) { //First we read our arguments from the command line while ((c = getopt (argc, argv, "kl:vrw:p:")) != -1) switch(c) { case 'l': listenPort = optarg; lflag = 1; break; case 'k': kflag = 1; break; case 'v': vflag = 1; break; case 'w': wflag = 1; timeOut = atoi(optarg); break; case 'r': rflag = 1; break; case 'p': pflag = 1; sourcePort = atoi(optarg); break; default: usage(argv[0]); exit(1); } //Get hostname and destination port only if -l is not on if (lflag != 1){ argn = optind; hostName = argv[argn]; //Make sure a port was provided in argv, or we will get a seg fault if(argn+1 >= argc){ usage(argv[0]); exit(1); } else { destPort = argv[argn+1]; } } //It is an error to use the -k option without the -l option. if(kflag == 1 && lflag == 0){ usage(argv[0]); exit(1); } //It is an error to use the -p option in conjunction with the -l option. if (lflag == 1 && pflag ==1){ usage(argv[0]); exit(1); } //The r option can only be used with the -l option if (rflag == 1 && lflag == 0){ usage(argv[0]); exit(1); } //The w cannot be used with the l option if (wflag == 1 && lflag == 1){ usage(argv[0]); exit(1); } //For debugging if(vflag){ printf ("kflag = %d, lflag = %d, vflag = %d, wflag= %d, rflag= %d, pflag =%d\n", kflag, lflag, vflag, wflag, rflag, pflag); printf("The time out is : %d\n", timeOut); printf("The sourcePort num is : %d\n", sourcePort); printf("The listenPort num is : %s\n", listenPort); printf("The hostName num is : %s\n", hostName); printf("The destPort num is : %s\n", destPort); } //Call server() function for -l flag if(lflag){ server(listenPort, kflag); } //For client if(lflag == 0){ client(hostName, destPort); } return 0; }
bool SpellChecker::canCheckAsynchronously(Node* node) const { return client() && isCheckable(node) && isAsynchronousEnabled() && !isBusy(); }
int main(int argc, char *argv[]) { if (argc < 3) { printf( "Usage: %s <statsd_host> <statsd_port> [<eth_interface>] [<refresh_rate_seconds>]\n" " where: eth_interface - default: eth0\n" " refresh_rate_seconds - default: 1\n\n" "Example: %s 127.0.0.1 8125\n", argv[0], argv[0]); exit(1); } string statsdHost = argv[1]; int statsdPort = atoi(argv[2]); string ethInterface = "eth0"; int refreshSeconds = 1; if (argc > 3) { ethInterface = argv[3]; if (argc == 5) { refreshSeconds = atoi(argv[4]); } } signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, SIG_IGN); /* will save one syscall per sleep */ signal(SIGTERM, sigterm); string ns = string("himond.") + getHostname().c_str() + "."; statsd::StatsdClient client(statsdHost, statsdPort, ns); SystemMonitor *sysmon = new SystemMonitor(true, true, true, ethInterface, refreshSeconds); printf("himond - running in background...\n"); daemon(0,0); int secondsPassed = 0; unsigned long uptime, memTotal, memUsed, memFree, virtMemTotal, virtMemUsed, virtMemFree, diskTotal, diskUsed, diskFree; unsigned long long diskReadRate, diskWriteRate, netRecvRate, netSendRate; int cpuCount; float cpuUsage; while (running) { sleep(1); secondsPassed++; // gathering stats uptime = sysmon->getSystemUptime(); // secs // MB memTotal = sysmon->getMemoryTotal(); memUsed = sysmon->getMemoryUsed(); memFree = sysmon->getMemoryFree(); // MB virtMemTotal = sysmon->getVirtualMemoryTotal(); virtMemUsed = sysmon->getVirtualMemoryUsed(); virtMemFree = sysmon->getVirtualMemoryFree(); // MB diskTotal = sysmon->getDiskTotal(); diskUsed = sysmon->getDiskUsed(); diskFree = sysmon->getDiskFree(); // kbps diskReadRate = sysmon->getDiskReadRate(); diskWriteRate = sysmon->getDiskWriteRate(); // kbps netRecvRate = sysmon->getRxRate(); netSendRate = sysmon->getTxRate(); cpuCount = sysmon->getProcessorCount(); cpuUsage = sysmon->getProcessorUsage(); if (refreshSeconds >= secondsPassed) { // send the stats client.count("system.uptime", uptime); client.gauge("memory.total", memTotal); client.gauge("memory.used", memUsed); client.gauge("memory.free", memFree); client.gauge("memory.virtual.total", virtMemTotal); client.gauge("memory.virtual.used", virtMemUsed); client.gauge("memory.virtual.free", virtMemFree); client.gauge("disk.total", diskTotal); client.gauge("disk.used", diskUsed); client.gauge("disk.free", diskFree); client.count("disk.rate.read", diskReadRate); client.count("disk.rate.write", diskWriteRate); client.count("net.rate.recv", netRecvRate); client.count("net.rate.send", netSendRate); client.gauge("cpu.count", cpuCount); client.gauge("cpu.usage", cpuUsage); secondsPassed = 0; } } return 0; }
int main(int argc, char **argv) { int uvmem_fd = open(DEV_UVMEM, O_RDWR); if (uvmem_fd < 0) { perror("can't open "DEV_UVMEM); exit(EXIT_FAILURE); } printf("uvmem_fd %d\n", uvmem_fd); long page_size = sysconf(_SC_PAGESIZE); printf("_SC_PAGESIZE = %ld\n", page_size); struct uvmem_init uinit = { .size = UVMEM_NR_PAGES * page_size, }; printf("UVMEM_INIT = %lu\n", UVMEM_INIT); if (ioctl(uvmem_fd, UVMEM_INIT, &uinit) < 0) { err(EXIT_FAILURE, "UVMEM_INIT"); } int shmem_fd = uinit.shmem_fd; size_t size = uinit.size; if (ftruncate(shmem_fd, size) < 0) { err(EXIT_FAILURE, "truncate(\"shmem_fd\")"); } printf("uvmem_fd %d shmem_fd %d\n", uvmem_fd, shmem_fd); fflush(stdout); #if 0 // fork based pid_t child = fork(); if (child < 0) { err(EXIT_FAILURE, "fork"); } if (child == 0) { // sleep(1); printf("server pid: %d\n", getpid()); server(uvmem_fd, shmem_fd, size, page_size); return 0; } #else DPRINTF("mmap\n"); void *ram = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, uvmem_fd, 0); if (ram == MAP_FAILED) { err(EXIT_FAILURE, "client: mmap"); } shared_mem = ram; pthread_t server_thread; pthread_attr_t attr; int rc; struct server_arg sarg = { .uvmem_fd = uvmem_fd, .shmem_fd = shmem_fd, .size = size, .page_size = page_size, }; rc = pthread_attr_init(&attr); if (rc) err(EXIT_FAILURE, "pthread_attr_init"); rc = pthread_create(&server_thread, &attr, thread_server, &sarg); printf("Thread id %u\n", (unsigned int)server_thread); if (rc) err(EXIT_FAILURE, "pthread_create"); #endif // printf("qemu pid: %d server pid: %d\n", getpid(), child); // close(shmem_fd); // sleep(1); /* wait the daemon is ready * To make it sure, communication with the server * is needed. sleep() is used here for simplicity. */ client(uvmem_fd, size, page_size); return 0; }
int main(int argc, char * const argv[]) { return client(argc, argv, connect_ssl); }
void InbandTextTrackPrivateAVF::processCue(CFArrayRef attributedStrings, double time) { if (!client()) return; if (m_havePartialCue) { // Cues do not have an explicit duration, they are displayed until the next "cue" (which might be empty) is emitted. m_currentCueEndTime = time; if (m_currentCueEndTime >= m_currentCueStartTime) { for (size_t i = 0; i < m_cues.size(); i++) { GenericCueData* cueData = m_cues[i].get(); cueData->setEndTime(m_currentCueEndTime); cueData->setStatus(GenericCueData::Complete); LOG(Media, "InbandTextTrackPrivateAVF::processCue(%p) - updating cue: start=%.2f, end=%.2f, content=\"%s\"", this, cueData->startTime(), m_currentCueEndTime, cueData->content().utf8().data()); client()->updateGenericCue(this, cueData); } } else LOG(Media, "InbandTextTrackPrivateAVF::processCue negative length cue(s) ignored: start=%.2f, end=%.2f\n", m_currentCueStartTime, m_currentCueEndTime); resetCueValues(); } if (!attributedStrings) return; CFIndex count = CFArrayGetCount(attributedStrings); if (!count) return; for (CFIndex i = 0; i < count; i++) { CFAttributedStringRef attributedString = static_cast<CFAttributedStringRef>(CFArrayGetValueAtIndex(attributedStrings, i)); if (!attributedString || !CFAttributedStringGetLength(attributedString)) continue; RefPtr<GenericCueData> cueData = GenericCueData::create(); processCueAttributes(attributedString, cueData.get()); if (!cueData->content().length()) continue; m_cues.append(cueData); m_currentCueStartTime = time; cueData->setStartTime(m_currentCueStartTime); cueData->setEndTime(numeric_limits<double>::infinity()); // duration // AVFoundation cue "position" is to the center of the text so adjust relative to the edge because we will use it to // set CSS "left". if (cueData->position() >= 0 && cueData->size() > 0) cueData->setPosition(cueData->position() - cueData->size() / 2); LOG(Media, "InbandTextTrackPrivateAVF::processCue(%p) - adding cue for time = %.2f, position = %.2f, line = %.2f", this, cueData->startTime(), cueData->position(), cueData->line()); cueData->setStatus(GenericCueData::Partial); client()->addGenericCue(this, cueData.release()); m_havePartialCue = true; } }
int test_main(int argc, char **argv) { //util::CommandLineOption<int> port("port", util::Ports::getNext(), "port number"); util::CommandLine::getSingleton().parse(argc, argv); int port = 0; std::vector<std::string> ips; ips.push_back("www.usatoday.com"); ips.push_back("www.sunet.se"); ips.push_back("www.google.com"); X x; { port = util::Ports::getNext(); RCF::RcfServer server(port); server.setAllowedClientIps(ips); server.bind<I_X>(x); server.start(); try { RcfClient<I_X> client("localhost", port); client.f(); BOOST_CHECK(1==0); } catch(const RCF::Exception &e) { RCF_TRACE("")(e); BOOST_CHECK(1==1); } ips = server.getAllowedClientIps(); ips.push_back("localhost"); server.setAllowedClientIps(ips); RcfClient<I_X> client("localhost", port); client.f(); } // test interface restriction // loopback interface std::vector<std::string> interfaces; interfaces.push_back("127.0.0.1"); interfaces.push_back("localhost"); for (unsigned int i=0; i<interfaces.size(); i++) { port = util::Ports::getNext(); RCF::RcfServer server(port); server.bind<I_X>(x); server.setNetworkInterface(interfaces[i]); server.start(); RcfClient<I_X>("localhost", port).f(); BOOST_CHECK(1==1); } // erroneous interface { port = util::Ports::getNext(); RCF::RcfServer server(port); server.bind<I_X>(x); server.setNetworkInterface("1.2.3.4"); try { server.start(); BOOST_CHECK(1==0); } catch (const RCF::Exception &e) { BOOST_CHECK(1==1); RCF_TRACE("")(e); } } return boost::exit_success; }
int UavcanNode::save_params(int remote_node_id) { uavcan::protocol::param::ExecuteOpcode::Request opcode_req; opcode_req.opcode = opcode_req.OPCODE_SAVE; uavcan::ServiceClient<uavcan::protocol::param::ExecuteOpcode, ExecuteOpcodeCallback> client(_node); client.setCallback(ExecuteOpcodeCallback(this, &UavcanNode::cb_opcode)); _callback_success = false; int call_res = client.call(remote_node_id, opcode_req); if (call_res >= 0) { while (client.hasPendingCalls()) { usleep(10000); } } if (!_callback_success) { std::printf("Failed to save parameters: %d\n", call_res); return -1; } return 0; }
int main(int argc, char* argv[]) { if (getpid() != 1) return client(argc, argv); /* * Hello world. */ banner(); /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/proc/bus/usb", "usbfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); makedir("/dev/pts", 0755); makedir("/dev/shm", 0755); mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620"); mount("none", "/dev/shm", "tmpfs", 0, NULL); umask(022); /* * Parse kernel parameters */ parse_kernel_cmdline(); /* * Populate /dev and prepare for runtime events from kernel. */ //run_interactive(SETUP_DEVFS, "Populating device tree"); // Todo mei Grampf /* * Parse configuration file */ parse_finit_conf(FINIT_CONF); /* * Load plugins. Must run after finit.conf has registered * all services, or service plugins won't have anything to * hook on to. */ print_desc("Loading plugins", NULL); print_result(plugin_load_all(PLUGIN_PATH)); /* * Mount filesystems */ #ifdef REMOUNT_ROOTFS_RW run("/bin/mount -n -o remount,rw /"); #endif #ifdef SYSROOT run(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); run("/bin/mount -na"); run("/sbin/swapon -ea"); umask(0022); /* Cleanup stale files, if any still linger on. */ run_interactive("rm -rf /tmp/* /var/run/* /var/lock/*", "Cleanup temporary directories"); /* Base FS up, enable standard SysV init signals */ sig_setup(); _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); /* * Start all bootstrap tasks, no network available! */ svc_bootstrap(); /* * Network stuff */ /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null"); /* Set initial hostname. */ set_hostname(&hostname); ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); if (network) run_interactive(network, "Starting networking: %s", network); umask(022); /* Hooks that rely on loopback, or basic networking being up. */ plugin_run_hooks(HOOK_NETWORK_UP); /* * Start all tasks/services in the configured runlevel */ svc_runlevel(cfglevel); _d("Running svc up hooks ..."); plugin_run_hooks(HOOK_SVC_UP); /* * Run startup scripts in /etc/finit.d/, if any. */ if (rcsd && fisdir(rcsd)) { _d("Running startup scripts in %s ...", rcsd); run_parts(rcsd, NULL); } /* Hooks that should run at the very end */ plugin_run_hooks(HOOK_SYSTEM_UP); /* * Enter main loop to monior /dev/initctl and services */ return run_loop(); }
bool MsgEdit::send() { unsigned i; Contact *contact = getContacts()->contact(m_msg->contact()); string client_str = m_msg->client(); bool bSent = false; void *data = NULL; if (contact){ Event e(EventMessageSend, m_msg); e.process(); if (client_str.empty()){ m_type = m_msg->type(); Client *c = client(data, true, false, m_msg->contact(), (m_msg->getFlags() & MESSAGE_MULTIPLY) == 0); if (c){ m_msg->setClient(c->dataName(data).c_str()); bSent = c->send(m_msg, data); }else{ data = NULL; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (client->send(m_msg, NULL)){ bSent = true; break; } } } }else{ ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ if (it.client()->dataName(data) == client_str){ if (it.client()->send(m_msg, data)) bSent = true; break; } } } } if (bSent){ if (data){ time_t now; time(&now); ((clientData*)data)->LastSend = now; } }else{ if (m_msg){ delete m_msg; m_msg = NULL; } stopSend(); CToolButton *btnSend = NULL; Command cmd; cmd->id = CmdSend; cmd->param = this; Event e(EventCommandWidget, cmd); btnSend = (CToolButton*)(e.process()); QWidget *msgWidget = btnSend; if (msgWidget == NULL) msgWidget = this; BalloonMsg::message(i18n("No such client for send message"), msgWidget); return false; } return true; }
void CoordinatedGraphicsLayer::didChangeFilters() { m_shouldSyncFilters = true; if (client()) client()->notifyFlushRequired(this); }