コード例 #1
0
ファイル: wrekavoc.c プロジェクト: TheProjecter/wrekagrid
/**
 * \brief function to check a node
 *
 * \param name name of the node to check
 * \param target ---
 * \return exit code, 0 if ok
 * \see ---
 *
 */
int checkHost (char *name, char *target)
{
  char buff;
  /*	Open a socket	*/
  int sockfd = startClientSocket (PORT, name);
  /*	Send "check"	*/
  if ((write (sockfd, "check\0    ", 10)) < 0) {
    perror ("ERROR writing to socket");
    exit (-8);
  }

  printf ("Checking %s state...\n\n", name);

  if ((write (sockfd, target, 1 + strlen (target))) < 0) {
    perror ("ERROR writing to socket");
    exit (-8);
  }

  printf ("Current configuration on %s :\n", name);

  /* The client will receive data until the server decide to
   * shut down the connection */
  while (read (sockfd, &buff, 1) != 0)
    printf ("%c", buff);

  close (sockfd);
  return 0;
}
コード例 #2
0
bool NetSerial::checkAndRestoreConnection(bool throttle)
{
	if (is_stopped_) {
		return false;
	}
	if (sockfd_ < 0 && throttle) {
		clock_t now = clock();
		// Only attempt to establish the connection every 5 seconds
		if (((now - lastConnectAttempt_) / CLOCKS_PER_SEC) < 5) {
			return false;
		}
	}
	lastConnectAttempt_ = clock();
	if (is_server_) {
		if (!startServerSocket()) {
			return false;
		}
		if (!acceptClient()) {
			return false;
		}
	} else {
		if (!startClientSocket()) {
			return false;
		}
	}
	return true;
}
コード例 #3
0
ファイル: wrekavoc.c プロジェクト: TheProjecter/wrekagrid
/**
 * \brief function to send xml structure to nodes
 *
 * \param xmldoc xml structure to send
 * \return exit code, 0 if ok
 * \see ---
 *
 */
int sendXml (char *xmldoc)
{
  FILE *fd;
  xmlDocPtr doc;
  xmlNodePtr node1, node2;
  xmlChar *islet_name, *node_name;
  int nb;
  char buff[512];
  int sockfd[100000], nbsock, i = 0;

  /* Each server ip adress are read in the xml file and a socket
   * is created for each and stored in an array */
  doc = xmlParseFile (xmldoc);
  node1 = doc->children->children->next;
  while (node1 && !strcmp (node1->name, "islet")) {
    islet_name = xmlGetProp (node1, "name");
    node2 = node1->children->next->next->next;
    while (node2) {
      node_name = xmlGetProp (node2, "name");
      printf ("  -> sending configuration to %s in %s\n",
	      node_name, islet_name);
      sockfd[i] = startClientSocket (PORT, node_name);
      if ((write (sockfd[i], "order\0    ", 10)) < 0) {
	perror ("ERROR writing to socket");
	exit (-8);
      }

      xmlFree (node_name);
      node2 = node2->next->next;
      i++;
    }
    xmlFree (islet_name);
    node1 = node1->next->next;
  }
  xmlFreeDoc (doc);
  nbsock = i;

  if ((fd = fopen (xmldoc, "r")) == NULL) {
    perror ("Error opening the configuration file");
    exit (-7);
  }

  /* Each string of 512 char from the configuration file are sent to
   * each socket. In this way, the file is read only one time, but
   * there is probably a better solution for sending the same data to
   * several socket or receiver */
  //TODO:Improve the transfert of data, if possible
  while (!feof (fd)) {
    nb = fread (buff, 1, 512, fd);
    for (i = 0; i < nbsock; i++) {
      write (sockfd[i], buff, nb);
    }
  }

  for (i = 0; i < nbsock; i++) {
    shutdown (sockfd[i], 1);
  }
  fclose (fd);
  return 0;
}
コード例 #4
0
ファイル: clipboardmonitor.cpp プロジェクト: lmbrt/CopyQ
ClipboardMonitor::ClipboardMonitor(int &argc, char **argv)
    : Client()
    , App(createPlatformNativeInterface()->createMonitorApplication(argc, argv))
    , m_formats()
    , m_newdata()
    , m_updateTimer( new QTimer(this) )
    , m_needCheckClipboard(false)
#ifdef COPYQ_WS_X11
    , m_needCheckSelection(false)
    , m_x11(new PrivateX11)
#endif
#ifdef Q_OS_MAC
    , m_prevChangeCount(0)
    , m_clipboardCheckTimer(new MacTimer(this))
    , m_macPlatform(new MacPlatform())
#endif
{
    Q_ASSERT(argc == 3);
    const QString serverName( QString::fromUtf8(argv[2]) );

#ifdef HAS_TESTS
    if ( serverName == QString("copyq_TEST") )
        QCoreApplication::instance()->setProperty("CopyQ_testing", true);
#endif

    m_updateTimer->setSingleShot(true);
    m_updateTimer->setInterval(300);
    connect( m_updateTimer, SIGNAL(timeout()),
             this, SLOT(updateTimeout()));

#ifdef COPYQ_WS_X11
    connect( &m_x11->incompleteSelectionTimer(), SIGNAL(timeout()),
             this, SLOT(updateSelection()) );
    connect( &m_x11->syncTimer(), SIGNAL(timeout()),
             this, SLOT(synchronize()) );
    connect( &m_x11->resetClipboardTimer(), SIGNAL(timeout()),
             this, SLOT(resetClipboard()) );
#endif

#ifdef Q_OS_MAC
    m_clipboardCheckTimer->setInterval(250);
    m_clipboardCheckTimer->setTolerance(500);
    connect(m_clipboardCheckTimer, SIGNAL(timeout()), this, SLOT(clipboardTimeout()));
    m_clipboardCheckTimer->start();
#endif

    Arguments arguments(argc, argv);
    if ( !startClientSocket(serverName, arguments) )
        exit(1);
}
コード例 #5
0
ファイル: wrekavoc.c プロジェクト: TheProjecter/wrekagrid
/**
 * \brief function to resetconfiguration
 *
 * \param xmldoc 
 * \return exit code, 0 if ok
 * \see ---
 *
 */
int Back2normalHost (char *xmldoc)
{
  int fd;
  xmlDocPtr doc;
  xmlXPathContextPtr xpathCtx;
  xmlXPathObjectPtr xpathObj;
  int size;
  xmlNodeSetPtr nodes;
  int i;

  printf ("Loading Xml...\n\n");
  if ((fd = open (xmldoc, O_RDONLY)) == -1) {
    perror ("Error opening the configuration file");
    exit (-7);
  }

  printf ("Checking Xml...\n\n");
  checkXml (xmldoc);
  doc = xmlParseFile (xmldoc);

  printf ("Sending Xml...\n");

  xpathCtx = xmlXPathNewContext (doc);
  xpathObj = xmlXPathEvalExpression ("//machine", xpathCtx);

  nodes = xpathObj->nodesetval;
  size = (nodes) ? nodes->nodeNr : 0;

  for (i = size - 1; i >= 0; i--) {
    int sockfd =
      startClientSocket (PORT, xmlGetProp (nodes->nodeTab[i], "name"));
    printf ("  -> reseting %s\'s state...\n",
	    xmlGetProp (nodes->nodeTab[i], "name"));
    if ((write (sockfd, "normal\0   ", 10)) < 0) {
      perror ("ERROR writing to socket");
      exit (-8);
    }
    close (sockfd);
  }

  xmlFreeDoc (doc);
  close (fd);
  return 0;
}