static void _as_activateAs(AS* h, int sd, uint32_t events) {
	struct partner_s *partner;
	int lsd = sd;
	partner = g_hash_table_lookup(h->hashmap, &lsd);

	if (partner == NULL && !IS_NEW_CONNECTION(sd)) {
		h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
				"Null pointer in lookup of %d (partner).", sd);
		_exit(EXIT_FAILURE);
	}

	h->slogf(SHADOW_LOG_LEVEL_MESSAGE, __FUNCTION__,
			"In the activate %d.", sd);

	if(events & EPOLLIN) {
		int res = 0;
		h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
				"EPOLLIN is set %d", sd);
		if (IS_NEW_CONNECTION(sd))
			handleNewConnection(h, sd);
		else
			res = handleRead(h, sd, partner);

		if (res > 0) {
			/* close the connection, some error (like EPIPE)
			 * occurred in the read. */
			closeConnections(h, sd, partner);
		} else if (res < 0) {
			/* Fatal error occurred. */
			_exit(EXIT_FAILURE);
		}
	}

	if(events & EPOLLOUT) {
		struct partner_s *me = g_hash_table_lookup(h->hashmap, &partner->sd);

		if (me == NULL) {
			if (h->isDone == 1){
				/* If it reaches this point, it means that the other 
			   		end point closed its socket descriptior (connection closed).
			   		Thus this socked descriptor must be closed too. */
				closeConnections(h, sd, partner);
			}else{
				h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
					"Null pointer in lookup of %d (me) (connection closed).", sd);
				_exit(EXIT_FAILURE);
			}
		}else{

			h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
				"EPOLLOUT is set %d", sd);
			handleWrite(h, sd, partner->sd, me);
		}
	}

}
Esempio n. 2
0
 int initTransport() {
     if (context) return -1;
     context = new zmq::context_t(NUM_IO_THREADS);        
     if (!context) return -1;
     if (Socks.size()>0) closeConnections();
     return 0;
 }
Esempio n. 3
0
//------------------------------------------------------------------------------
// Send and receive test messages
//------------------------------------------------------------------------------
void Echo::updateData(const Eaagles::LCreal dt)
{
    // Update base classes stuff
    BaseClass::updateData(dt);

    if (areNetworksEnabled()) {
        // Looking for a message from the client
        char buffer[MAX_SIZE+1];
        unsigned int n = recvData(buffer, MAX_SIZE);
        std::cout << "n = " << n << std::endl;
        if (n > 0) {
            buffer[n] = 0;
            std::cout << "RECV: " << buffer << std::endl;
            // And send it right back to the client
            Eaagles::lcSleep(1000);
            bool ok = sendData(buffer, n);
            if (ok) {
               std::cout << "SENT: " << buffer << std::endl << std::endl;

               // End check
               loopCounter++;
               if (getLoops() > 0 && loopCounter >= getLoops()) {
                   closeConnections();
                   std::cout << "Exit: " << getLoops() << " loops completed!" << std::endl;
                   std::exit(0);
               }

            }
        }
    }
}
Esempio n. 4
0
 /*
  * It closes the transport layer, close all connections to any active
  * end-point and delete the existing context.
  *
  * \returns 0 is returned to show the successful closing of transport
  * connection.
  */
 int closeTransport() {
     closeConnections();
     if (context) {
         delete context;
         context=NULL;
     }
     return 0;
 }
ChatManager::~ChatManager()
{
    closeConnections();

    if ( _p_chatGuiCtrl )
        delete _p_chatGuiCtrl;

    if ( _p_chatGuiBox )
        delete _p_chatGuiBox;

    // deregister for getting application window state changes
    yaf3d::GameState::get()->registerCallbackAppWindowStateChange( this, false );
}
Esempio n. 6
0
static void
ip_status_cb(struct netif* netif)
{
	INFO_INIT("IP status cb...\n");
        if (netif_is_up(netif)) {
            set_result_cmd(WL_SUCCESS);
            printk("bound to %s\n", ip2str(netif->ip_addr));
            ifStatus = true;
        }else{
        	ifStatus = false;
        	closeConnections();
        	WARN("Interface not up!\n");
        }
}
Esempio n. 7
0
//------------------------------------------------------------------------------
// Serialize and write a DataRecord to a network
//------------------------------------------------------------------------------
void NetOutput::processRecordImp(const DataRecordHandle* const handle)
{
   bool thisIsEodMsg = false;

   // ---
   // Open the file, if it hasn't been already ...
   // ---
   if ( !networkInitialized && !networkInitFailed ) initNetworks();

   if (handle != 0 && networkInitialized && netHandler->isConnected()) {

      // The DataRecord to be sent
      const Pb::DataRecord* dataRecord = handle->getRecord();

      // Serialize the DataRecord
      std::string wireFormat;
      bool ok = dataRecord->SerializeToString(&wireFormat);

      // Write the serialized message to the network
      if (ok) {
         netHandler->sendData( wireFormat.c_str(), wireFormat.length() );
      }

      else if (isMessageEnabled(MSG_ERROR | MSG_WARNING)) {
         // If we had an error serializing the DataRecord
         std::cerr << "NetOutput::processRecordImp() -- SerializeToString() error" << std::endl;
      }

      // Check for END_OF_DATA message
      thisIsEodMsg = (dataRecord->id() == REID_END_OF_DATA);

   }

   // ---
   // Close the file at END_OF_DATA message
   // ---
   if (thisIsEodMsg) {
      closeConnections();
   }
}
Esempio n. 8
0
//------------------------------------------------------------------------------
// deleteData() -- delete member data
//------------------------------------------------------------------------------
void NetOutput::deleteData()
{
   closeConnections();
   netHandler = 0;
}
Esempio n. 9
0
//------------------------------------------------------------------------------
// deleteData() -- delete member data
//------------------------------------------------------------------------------
void NetInput::deleteData()
{
   closeConnections();
   netHandler = 0;
   if (ibuf != 0) { delete[] ibuf; ibuf = 0; }
}