Exemplo n.º 1
0
	/** This should be only called when the client is ready to receive a response to the requestUrl.
	* Returns true if something is sended.
	* Returns false if there is nothing to send yet. (longpoll mode)
    */
	bool respond(bool abort=false)
	{
		bool sended;

		//someone requested the special longpoll url:
		if (mRequestUrl=="/synapse/longpoll")
		{
			sended=(respondJsonQueue(abort));
		}
		//just respond with a normal file
		else
		{
			sended=(respondFile(mRequestUrl));
		}

		//what to do after the response?
		if (sended)
		{
			if (mHeaders.isSet("connection"))
			{
				if (mHeaders["connection"].str()=="close")
					doDisconnect();
			}
			else if (mRequestVersion=="1.0")
			{
				//http 1.0 should always disconnect if Connection: Keep-Alive is not specified.
				doDisconnect();
			}
		}

		return (sended);
	}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// 描述: 断开数据库连接并进行相关设置
//-----------------------------------------------------------------------------
void DbConnection::disconnect()
{
    if (isConnected_)
    {
        doDisconnect();
        isConnected_ = false;
    }
}
SCI_Transporter::~SCI_Transporter() { 
  DBUG_ENTER("SCI_Transporter::~SCI_Transporter");
  // Close channel to the driver 
  doDisconnect(); 
  if(m_sendBuffer.m_buffer != NULL)
    delete[] m_sendBuffer.m_buffer;
  DBUG_VOID_RETURN;
} // ~SCI_Transporter() 
Exemplo n.º 4
0
void doAdmin(int sock, ControlStruct *p)
{
   char *cp, *cp1, tmpBuf[20];
   int x;

   if (dbg) syslog(LOG_DEBUG, "doAdmin():Enter |%s|", p->buf);
   if (p->passwdMode != 0) 
   {
      doPrivilege(p, "", sock);
   }
   else
   {
      for (cp = p->buf; *cp != '\0' && isspace(*cp); cp++);
      memset(tmpBuf, '\0', sizeof(tmpBuf));
      for (x = 0, cp1 = tmpBuf; *cp != '\0' && !isspace(*cp) && (unsigned)x < sizeof(tmpBuf); x++)
      {
         *(cp1++) = tolower(*cp++);
         *cp1 = '\0';
      }
      if (dbg) syslog(LOG_DEBUG, "doAdmin():Command = |%s|", tmpBuf);
      for (; *cp != '\0' && isspace(*cp); cp++);

      if (dbg) syslog(LOG_DEBUG, "doAdmin():Remainder Command = |%s|", cp);

      if (strcmp(tmpBuf, "enable") == 0)
         doEnable(p, cp);

      else if (strcmp(tmpBuf, "disable") == 0)
         doDisable(p, cp);

      else if (strcmp(tmpBuf, "disconnect") == 0)
         doDisconnect(p, cp);

//      else if (strcmp(tmpBuf, "privilege") == 0)
//         doPrivilege(p, cp, sock);

      else if (strcmp(tmpBuf, "set") == 0)
         doSet(p, cp);

      else if (strcmp(tmpBuf, "help") == 0)
         doHelp(p, cp);

      else if (strcmp(tmpBuf, "show") == 0)
         doShow(p, cp);

      else if (strcmp(tmpBuf, "verbose") == 0)
         p->verbose = (p->verbose == 0) ? 1 : 0;

      else 
      {
         if (p->verbose)
            fputs("Error, Command Not recognized\n", p->fp);
         else
            fputs("904:Command Not recognized\n", p->fp);
      }
   }
   fflush(p->fp);
}
Exemplo n.º 5
0
TCP_Transporter::~TCP_Transporter() {
  
  // Disconnect
  if (my_socket_valid(theSocket))
    doDisconnect();
  
  // Delete receive buffer!!
  receiveBuffer.destroy();
}
Exemplo n.º 6
0
int
TCP_Transporter::doReceive() {
  // Select-function must return the socket for read
  // before this method is called
  // It reads the external TCP/IP interface once
  Uint32 size = receiveBuffer.sizeOfBuffer - receiveBuffer.sizeOfData;
  if(size > 0){
    const int nBytesRead = recv(theSocket, 
				receiveBuffer.insertPtr, 
				size < maxReceiveSize ? size : maxReceiveSize, 
				0);
    
    if (nBytesRead > 0) {
      receiveBuffer.sizeOfData += nBytesRead;
      receiveBuffer.insertPtr  += nBytesRead;
      
      if(receiveBuffer.sizeOfData > receiveBuffer.sizeOfBuffer){
#ifdef DEBUG_TRANSPORTER
	g_eventLogger.error("receiveBuffer.sizeOfData(%d) > receiveBuffer.sizeOfBuffer(%d)",
		 receiveBuffer.sizeOfData, receiveBuffer.sizeOfBuffer);
	g_eventLogger.error("nBytesRead = %d", nBytesRead);
#endif
	g_eventLogger.error("receiveBuffer.sizeOfData(%d) > receiveBuffer.sizeOfBuffer(%d)",
		 receiveBuffer.sizeOfData, receiveBuffer.sizeOfBuffer);
	report_error(TE_INVALID_MESSAGE_LENGTH);
	return 0;
      }
      
      receiveCount ++;
      receiveSize  += nBytesRead;
      
      if(receiveCount == reportFreq){
	reportReceiveLen(get_callback_obj(), remoteNodeId, receiveCount, receiveSize);
	receiveCount = 0;
	receiveSize  = 0;
      }
      return nBytesRead;
    } else {
#if defined DEBUG_TRANSPORTER
      g_eventLogger.error("Receive Failure(disconnect==%d) to node = %d nBytesSent = %d "
	       "errno = %d strerror = %s",
	       DISCONNECT_ERRNO(InetErrno, nBytesRead),
	       remoteNodeId, nBytesRead, InetErrno, 
	       (char*)ndbstrerror(InetErrno));
#endif   
      if(DISCONNECT_ERRNO(InetErrno, nBytesRead)){
	// The remote node has closed down
	doDisconnect();
	report_disconnect(InetErrno);
      } 
    }
    return nBytesRead;
  } else {
    return 0;
  }
}
Exemplo n.º 7
0
bool
TCP_Transporter::doSend() {
  // If no sendbuffers are used nothing is done
  // Sends the contents of the SendBuffers until they are empty
  // or until select does not select the socket for write.
  // Before calling send, the socket must be selected for write
  // using "select"
  // It writes on the external TCP/IP interface until the send buffer is empty
  // and as long as write is possible (test it using select)

  // Empty the SendBuffers
  
  bool sent_any = true;
  while (m_sendBuffer.dataSize > 0)
  {
    const char * const sendPtr = m_sendBuffer.sendPtr;
    const Uint32 sizeToSend    = m_sendBuffer.sendDataSize;
    const int nBytesSent = send(theSocket, sendPtr, sizeToSend, 0);
    
    if (nBytesSent > 0) 
    {
      sent_any = true;
      m_sendBuffer.bytesSent(nBytesSent);
      
      sendCount ++;
      sendSize  += nBytesSent;
      if(sendCount == reportFreq)
      {
	reportSendLen(get_callback_obj(), remoteNodeId, sendCount, sendSize);
	sendCount = 0;
	sendSize  = 0;
      }
    } 
    else 
    {
      if (nBytesSent < 0 && InetErrno == EAGAIN && sent_any)
        break;

      // Send failed
#if defined DEBUG_TRANSPORTER
      g_eventLogger.error("Send Failure(disconnect==%d) to node = %d nBytesSent = %d "
	       "errno = %d strerror = %s",
	       DISCONNECT_ERRNO(InetErrno, nBytesSent),
	       remoteNodeId, nBytesSent, InetErrno, 
	       (char*)ndbstrerror(InetErrno));
#endif   
      if(DISCONNECT_ERRNO(InetErrno, nBytesSent)){
	doDisconnect();
	report_disconnect(InetErrno);
      }
      
      return false;
    }
  }
  return true;
}
Exemplo n.º 8
0
	bool sendData(const asio::mutable_buffers_1 & buffers)
	{
		if (write(tcpSocket,buffers) != buffer_size(buffers))
		{
			ERROR(id << " had write while sending data, disconnecting.");
			doDisconnect();
			return(false);
		}
		return(true);
	}
Exemplo n.º 9
0
TCP_Transporter::~TCP_Transporter() {
  
  // Disconnect
  if (theSocket != NDB_INVALID_SOCKET)
    doDisconnect();
  
  // Delete send buffers
  
  // Delete receive buffer!!
  receiveBuffer.destroy();
}
/**
 * For now implement truncate here and only for size == 0.
 * Weak implementation in that we just delete the file and 
 * then re-create it, but don't set the user, group, and times to the old
 * file's metadata. 
 */
int dfs_truncate(const char *path, off_t size)
{
  TRACE1("truncate", path)

  dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;

  assert(path);
  assert('/' == *path);
  assert(dfs);

  if (size != 0) {
    return -ENOTSUP;
  }

  int ret = dfs_unlink(path);
  if (ret != 0) {
    return ret;
  }

  hdfsFS userFS = doConnectAsUser(dfs->nn_hostname, dfs->nn_port);
  if (userFS == NULL) {
    ERROR("Could not connect");
    ret = -EIO;
    goto cleanup;
  }

  int flags = O_WRONLY | O_CREAT;

  hdfsFile file;
  if ((file = (hdfsFile)hdfsOpenFile(userFS, path, flags,  0, 0, 0)) == NULL) {
    ERROR("Could not connect open file %s", path);
    ret = -EIO;
    goto cleanup;
  }

  if (hdfsCloseFile(userFS, file) != 0) {
    ERROR("Could not close file %s", path);
    ret = -EIO;
    goto cleanup;
  }

cleanup:
  if (doDisconnect(userFS)) {
    ret = -EIO;
  }
  return ret;
}
Exemplo n.º 11
0
/*****************************************************************************
 * ~Ndb();
 *
 * Remark:        Disconnect with the database.
 *****************************************************************************/
Ndb::~Ndb()
{
    DBUG_ENTER("Ndb::~Ndb()");
    DBUG_PRINT("enter",("this: 0x%lx", (long) this));

    if (m_sys_tab_0)
        getDictionary()->removeTableGlobal(*m_sys_tab_0, 0);

    assert(theImpl->m_ev_op == 0); // user should return NdbEventOperation's
    for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next)
    {
        if (op->m_state == NdbEventOperation::EO_EXECUTING && op->stop())
            g_eventLogger.error("stopping NdbEventOperation failed in Ndb destructor");
        op->m_magic_number= 0;
    }
    doDisconnect();

    /* Disconnect from transporter to stop signals from coming in */
    if (theImpl->m_transporter_facade != NULL && theNdbBlockNumber > 0) {
        theImpl->m_transporter_facade->close(theNdbBlockNumber, theFirstTransId);
    }

    delete theEventBuffer;

    releaseTransactionArrays();

    delete []theConnectionArray;
    if(theCommitAckSignal != NULL) {
        delete theCommitAckSignal;
        theCommitAckSignal = NULL;
    }

    delete theImpl;

#ifdef POORMANSPURIFY
#ifdef POORMANSGUI
    ndbout << "cnewSignals=" << cnewSignals << endl;
    ndbout << "cfreeSignals=" << cfreeSignals << endl;
    ndbout << "cgetSignals=" << cgetSignals << endl;
    ndbout << "creleaseSignals=" << creleaseSignals << endl;
#endif
    // Poor mans purifier
    assert(cnewSignals == cfreeSignals);
    assert(cgetSignals == creleaseSignals);
#endif
    DBUG_VOID_RETURN;
}
Exemplo n.º 12
0
/*****************************************************************************
 * ~Ndb();
 *
 * Remark:        Disconnect with the database. 
 *****************************************************************************/
Ndb::~Ndb()
{ 
  DBUG_ENTER("Ndb::~Ndb()");
  DBUG_PRINT("enter",("Ndb::~Ndb this: 0x%lx",(long) this));
  doDisconnect();

  if (TransporterFacade::instance() != NULL && theNdbBlockNumber > 0){
    TransporterFacade::instance()->close(theNdbBlockNumber, theFirstTransId);
  }
  
  releaseTransactionArrays();

  delete []theConnectionArray;
  if(theCommitAckSignal != NULL){
    delete theCommitAckSignal; 
    theCommitAckSignal = NULL;
  }

  delete theImpl;

  /** 
   *  This sleep is to make sure that the transporter 
   *  send thread will come in and send any
   *  signal buffers that this thread may have allocated.
   *  If that doesn't happen an error will occur in OSE
   *  when trying to restore a signal buffer allocated by a thread
   *  that have been killed.
   */
#ifdef NDB_OSE
  NdbSleep_MilliSleep(50);
#endif

#ifdef POORMANSPURIFY
#ifdef POORMANSGUI
  ndbout << "cnewSignals=" << cnewSignals << endl;
  ndbout << "cfreeSignals=" << cfreeSignals << endl;
  ndbout << "cgetSignals=" << cgetSignals << endl;
  ndbout << "creleaseSignals=" << creleaseSignals << endl;
#endif
  // Poor mans purifier
  assert(cnewSignals == cfreeSignals);
  assert(cgetSignals == creleaseSignals);
#endif
  DBUG_VOID_RETURN;
}
Exemplo n.º 13
0
TestClient::TestClient()
    : KMainWindow( 0 ),
      m_status( AppDisconnected ), m_view( new QWidget( this ) )
{
    ui.setupUi( m_view );

    setCentralWidget(m_view);

    networkStatusChanged( Solid::Networking::status() );
    appDisconnected();

    kDebug() << "About to connect";
    connect( Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)), SLOT(networkStatusChanged(Solid::Networking::Status)) );
    kDebug() << "Connected.";
    connect( Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, SLOT(doConnect()) );
    connect( Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), this, SLOT(doDisconnect()) );

    connect( ui.connectButton, SIGNAL(clicked()), SLOT(connectButtonClicked()) );
}
Exemplo n.º 14
0
void ConnectDialog::on_pbConnect_toggled(bool checked)
{
    auto client = ClientConnection::Instance();
    if (checked) {
        if (ui->lePicsPath->text() == "") {
            Logger::error("Select folder with pics");
            return;
        }

        picsPath = ui->lePicsPath->text();
        if (picsPath.right(1) != "/")
            picsPath.append("/");

        client->doConnectToHost(ui->leHost->text(), ui->sbPort->value());
        ui->pbConnect->setText("Process...");
    } else {
        client->doDisconnect();
    }

}
Exemplo n.º 15
0
int dfs_statfs(const char *path, struct statvfs *st)
{
  TRACE1("statfs",path)

  dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;

  assert(path);
  assert(st);
  assert(dfs);

  memset(st,0,sizeof(struct statvfs));

  hdfsFS userFS = doConnectAsUser(dfs->nn_hostname, dfs->nn_port);
  if (userFS == NULL) {
    ERROR("Could not connect");
    return -EIO;
  }

  const tOffset cap   = hdfsGetCapacity(userFS);
  const tOffset used  = hdfsGetUsed(userFS);
  const tOffset bsize = hdfsGetDefaultBlockSize(userFS);

  if (doDisconnect(userFS)) {
    return -EIO;
  }

  st->f_bsize   =  bsize;
  st->f_frsize  =  bsize;
  st->f_blocks  =  cap/bsize;
  st->f_bfree   =  (cap-used)/bsize;
  st->f_bavail  =  (cap-used)/bsize;
  st->f_files   =  1000;
  st->f_ffree   =  500;
  st->f_favail  =  500;
  st->f_fsid    =  1023;
  st->f_flag    =  ST_RDONLY | ST_NOSUID;
  st->f_namemax =  1023;

  return 0;
}
Exemplo n.º 16
0
	// Received new data:
	void received(int id, asio::streambuf &readBuffer, std::size_t bytesTransferred)
	{
		string dataStr(boost::asio::buffer_cast<const char*>(readBuffer.data()), readBuffer.size());
		string error;

		//we're expecting a new request:
		if (mState==REQUEST || mState==WAIT_LONGPOLL)
		{
			//if there is still an outstanding longpoll, cancel it:
			if (mState==WAIT_LONGPOLL)
			{
				respond(true);
			}

			//resize data to first delimiter:
			dataStr.resize(dataStr.find(delimiter)+delimiter.length());
			readBuffer.consume(dataStr.length());

			DEB(id << " got http REQUEST: \n" << dataStr);

			//determine the kind of request:
 			smatch what;
 			if (!regex_search(
 				dataStr,
 				what,
 				boost::regex("^(GET|POST) ([^? ]*)([^ ]*) HTTP/(1..)$")
 			))
 			{
				error="Cant parse request.";
 			}
			else
			{
				mRequestType=what[1];
				mRequestUrl=what[2];
				mRequestQuery=what[3];
				mRequestVersion=what[4];
				DEB("REQUEST query: " << mRequestQuery);

				//create a regex iterator for http headers
				mHeaders.clear();
				boost::sregex_iterator headerI(
					dataStr.begin(),
					dataStr.end(),
					boost::regex("^([[:alnum:]-]*): (.*?)$")
				);

				//parse http headers
				while (headerI!=sregex_iterator())
				{
					string header=(*headerI)[1].str();
					string value=(*headerI)[2].str();

					//headers handling is lowercase in synapse!
					transform(header.begin(), header.end(), header.begin(), ::tolower);

					mHeaders[header]=value;
					headerI++;
				}

				//this header MUST be set on longpoll requests:
				//if the client doesnt has one yet, httpSessionMan will assign a new one.
				try
				{
					mAuthCookie=mHeaders["x-synapse-authcookie"];
				}
				catch(...)
				{
					mAuthCookie=0;
				}

				//proceed based on requestType:
				//a GET or empty POST:
				if (mRequestType=="GET" || (int)mHeaders["content-length"]==0)
				{
					if (respond())
					{
						mState=REQUEST;
					}
					else
					{
						DEB(id << " is now waiting for longpoll results");
						mState=WAIT_LONGPOLL;
					}
					return;
				}
				//a POST with content:
				else
				{
					if ( (int)mHeaders["content-length"]<0  || (int)mHeaders["content-length"] > config["maxContent"] )
					{
						error="Invalid Content-Length";
					}
					else
					{
						//change state to read the contents of the POST:
						mState=CONTENT;
						return;
					}
				}
			}
		}
		else
		//we're expecting the contents of a POST request.
		if (mState==CONTENT)
		{
			if (readBuffer.size() < mHeaders["content-length"])
			{
				error="Didn't receive enough content-bytes!";
				DEB(id <<  " ERROR: Expected " << mHeaders["content-length"].str() << " bytes, but only got: " << bytesTransferred);
			}
			else
			{
				dataStr.resize(mHeaders["content-length"]);
				readBuffer.consume(mHeaders["content-length"]);
				DEB(id << " got http CONTENT with length=" << dataStr.size() << ": \n" << dataStr);

				//POST to the special send url?
				if (mRequestUrl=="/synapse/send")
				{
					error=httpSessionMan.sendMessage(mAuthCookie, dataStr);
					if (error=="")
					{
						//DONT:respond with jsondata if we have something in the queue anyways
						//DONT:respondJsonQueue(false,false);
						//we cant do this, because then the order of messages isnt garanteed. so just respond with a boring empty string:
						respondString(200, "");
					}
					else
						respondError(400, error);

					mState=REQUEST;
					return;
				}
				else
				{
					//ignore whatever is posted, and just respond normally:
					DEB(id << " ignored POST content");
					if (respond())
						mState=REQUEST;
					else
						mState=WAIT_LONGPOLL;
					return;
				}
			}
		}

		//ERROR(id << " had error while processing http data: " << error);
		error="Bad request: "+error;
		respondError(400, error);
		doDisconnect();
		return;

	}
Exemplo n.º 17
0
void SCI_Transporter::setupRemoteSegment()   
{ 
   DBUG_ENTER("SCI_Transporter::setupRemoteSegment");
   Uint32 sharedSize = 0; 
   sharedSize =4096;   //start of the buffer is page aligned 
 
   Uint32 sizeOfBuffer = m_BufferSize; 
   const Uint32 slack = MAX_MESSAGE_SIZE;
   sizeOfBuffer -= sharedSize; 

   Uint32 *segPtr = (Uint32*) m_TargetSegm[m_ActiveAdapterId].mappedMemory ;   
    
   Uint32 * remoteReadIndex = (Uint32*)segPtr;  
   Uint32 * remoteWriteIndex = (Uint32*)(segPtr + 1); 
   m_remoteStatusFlag = (Uint32*)(segPtr + 3);
    
   char * remoteStartOfBuf = ( char*)((char*)segPtr+(sharedSize)); 
    
   writer = new SHM_Writer(remoteStartOfBuf,  
			   sizeOfBuffer, 
			   slack,
			   remoteReadIndex, 
			   remoteWriteIndex);
   
   writer->clear(); 
    
   m_TargetSegm[0].writer=writer; 
 
   m_sendBuffer.m_forceSendLimit = writer->getBufferSize();
    
   if(createSequence(m_ActiveAdapterId)!=SCI_ERR_OK) { 
     report_error(TE_SCI_UNABLE_TO_CREATE_SEQUENCE); 
     DBUG_PRINT("error", ("Unable to create sequence on active"));
     doDisconnect(); 
   } 
   if (m_adapters > 1) {
     segPtr = (Uint32*) m_TargetSegm[m_StandbyAdapterId].mappedMemory ; 
    
     Uint32 * remoteReadIndex2 = (Uint32*)segPtr;  
     Uint32 * remoteWriteIndex2 = (Uint32*) (segPtr + 1); 
     m_remoteStatusFlag2 = (Uint32*)(segPtr + 3);
    
     char * remoteStartOfBuf2 = ( char*)((char *)segPtr+sharedSize); 
    
     /** 
      * setup a writer. writer2 is used to mirror the changes of 
      * writer on the standby 
      * segment, so that in the case of a failover, we can switch 
      * to the stdby seg. quickly.* 
      */ 
     writer2 = new SHM_Writer(remoteStartOfBuf2,  
                              sizeOfBuffer, 
                              slack,
                              remoteReadIndex2, 
                              remoteWriteIndex2);

     * remoteReadIndex = 0; 
     * remoteWriteIndex = 0; 
     writer2->clear(); 
     m_TargetSegm[1].writer=writer2; 
     if(createSequence(m_StandbyAdapterId)!=SCI_ERR_OK) { 
       report_error(TE_SCI_UNABLE_TO_CREATE_SEQUENCE); 
       DBUG_PRINT("error", ("Unable to create sequence on standby"));
       doDisconnect(); 
     } 
   }
   DBUG_VOID_RETURN; 
} //setupRemoteSegment 
Exemplo n.º 18
0
SHM_Transporter::~SHM_Transporter(){
  doDisconnect();
}
Exemplo n.º 19
0
SCI_Transporter::~SCI_Transporter() { 
  DBUG_ENTER("SCI_Transporter::~SCI_Transporter");
  // Close channel to the driver 
  doDisconnect(); 
  DBUG_VOID_RETURN;
} // ~SCI_Transporter() 
Exemplo n.º 20
0
/*****************************************************************************
 * ~Ndb();
 *
 * Remark:        Disconnect with the database. 
 *****************************************************************************/
Ndb::~Ndb()
{ 
  DBUG_ENTER("Ndb::~Ndb()");
  DBUG_PRINT("enter",("this: 0x%lx", (long) this));

  if (m_sys_tab_0)
    getDictionary()->removeTableGlobal(*m_sys_tab_0, 0);

  if (theImpl->m_ev_op != 0)
  {
    g_eventLogger->warning("Deleting Ndb-object with NdbEventOperation still"
                           " active");
    printf("this: %p NdbEventOperation(s): ", this);
    for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next)
    {
      printf("%p ", op);
    }
    printf("\n");
    fflush(stdout);
  }

  assert(theImpl->m_ev_op == 0); // user should return NdbEventOperation's
  for (NdbEventOperationImpl *op= theImpl->m_ev_op; op; op=op->m_next)
  {
    if (op->m_state == NdbEventOperation::EO_EXECUTING && op->stop())
      g_eventLogger->error("stopping NdbEventOperation failed in Ndb destructor");
    op->m_magic_number= 0;
  }
  doDisconnect();

  /* Disconnect from transporter to stop signals from coming in */
  theImpl->close();

  delete theEventBuffer;

  releaseTransactionArrays();

  delete []theConnectionArray;
  delete []theConnectionArrayLast;
  if(theCommitAckSignal != NULL){
    delete theCommitAckSignal; 
    theCommitAckSignal = NULL;
  }

  theImpl->m_ndb_cluster_connection.unlink_ndb_object(this);

  delete theImpl;

#ifdef POORMANSPURIFY
#ifdef POORMANSGUI
  ndbout << "cnewSignals=" << cnewSignals << endl;
  ndbout << "cfreeSignals=" << cfreeSignals << endl;
  ndbout << "cgetSignals=" << cgetSignals << endl;
  ndbout << "creleaseSignals=" << creleaseSignals << endl;
#endif
  // Poor mans purifier
  assert(cnewSignals == cfreeSignals);
  assert(cgetSignals == creleaseSignals);
#endif
  DBUG_VOID_RETURN;
}
	QtUdpSocketPlugin::QtUdpSocketPlugin() : _socket(nullptr), _helperReceiveCallback(), _checkerReceiveCallback(), _messageCounter(0), _conditionLock(), _conditionVariable(), _targetHost(), _targetPort(0) {
		QObject::connect(this, SIGNAL(doListen(quint16)), this, SLOT(onListen(quint16)));
		QObject::connect(this, SIGNAL(doConnect(QString, quint16)), this, SLOT(onConnect(QString, quint16)));
		QObject::connect(this, SIGNAL(doSendMessage(QString)), this, SLOT(onSendMessage(QString)));
		QObject::connect(this, SIGNAL(doDisconnect()), this, SLOT(onDisconnect()));
	}
Exemplo n.º 22
0
sci_error_t SCI_Transporter::initLocalSegment() { 
  DBUG_ENTER("SCI_Transporter::initLocalSegment");
  Uint32 segmentSize = m_BufferSize; 
  Uint32 offset  = 0; 
  sci_error_t err; 
  if(!m_sciinit) { 
    for(Uint32 i=0; i<m_adapters ; i++) { 
      SCIOpen(&(sciAdapters[i].scidesc), FLAGS, &err); 
      sciAdapters[i].localSciNodeId=getLocalNodeId(i); 
      DBUG_PRINT("info", ("SCInode iD %d  adapter %d\n",  
	         sciAdapters[i].localSciNodeId, i)); 
      if(err != SCI_ERR_OK) { 
        DBUG_PRINT("error",
        ("Cannot open an SCI virtual device. Error code 0x%x", 
		   err)); 
	DBUG_RETURN(err); 
      } 
    } 
  } 
   
  m_sciinit=true; 
 
  SCICreateSegment(sciAdapters[0].scidesc,            
		   &(m_SourceSegm[0].localHandle),  
		   hostSegmentId(localNodeId, remoteNodeId),    
		   segmentSize,                
		   0, 
		   0, 
		   0,         
		   &err);             
   
  if(err != SCI_ERR_OK) { 
    DBUG_PRINT("error", ("Error creating segment, err = 0x%x", err));
    DBUG_RETURN(err); 
  } else { 
    DBUG_PRINT("info", ("created segment id : %d",
	       hostSegmentId(localNodeId, remoteNodeId))); 
  } 
   
  /** Prepare the segment*/ 
  for(Uint32 i=0; i < m_adapters; i++) { 
    SCIPrepareSegment((m_SourceSegm[0].localHandle),  
		      i, 
		      FLAGS, 
		      &err); 
     
    if(err != SCI_ERR_OK) { 
      DBUG_PRINT("error",
    ("Local Segment is not accessible by an SCI adapter. Error code 0x%x\n",
                  err)); 
      DBUG_RETURN(err); 
    } 
  } 
 
  
  m_SourceSegm[0].mappedMemory =  
    SCIMapLocalSegment((m_SourceSegm[0].localHandle), 
		       &(m_SourceSegm[0].lhm[0].map), 
		       offset, 
		       segmentSize, 
		       NULL, 
		       FLAGS, 
		       &err); 
 
 
 
  if(err != SCI_ERR_OK) { 
    DBUG_PRINT("error", ("Cannot map area of size %d. Error code 0x%x", 
	        segmentSize,err)); 
    doDisconnect(); 
    DBUG_RETURN(err); 
  } 
  
  
  /** Make the local segment available*/ 
  for(Uint32 i=0; i < m_adapters; i++) { 
    SCISetSegmentAvailable((m_SourceSegm[0].localHandle),  
			     i, 
			   FLAGS, 
			   &err); 
     
    if(err != SCI_ERR_OK) { 
      DBUG_PRINT("error",
   ("Local Segment is not available for remote connections. Error code 0x%x\n",
                 err)); 
      DBUG_RETURN(err); 
    } 
  } 
  setupLocalSegment(); 
  DBUG_RETURN(err); 
   
} // initLocalSegment() 
Exemplo n.º 23
0
	/** Respond by sending a file relative to the wwwdir/
	*/
	bool respondFile(string path)
	{
		Cvar extraHeaders;

		//FIXME: do a better way of checking/securing the path. Inode verification? Or compare with a filelist?
		if (path.find("..")!=string::npos)
		{
			respondError(403, "Path contains illegal characters");
			return(true);
		}

		//default path?
		if (path=="/")
		{
			path=config["indexFile"].str();
		}

		string localPath;
		localPath="wwwdir/"+path;

		struct stat statResults;
		int statError=stat(localPath.c_str(), &statResults);
		if (statError)
		{
			respondError(404, "Error while statting or file not found: " + path);
			return(true);
		}

		if (! (S_ISREG(statResults.st_mode)) )
		{
			respondError(404, "Path " + path + " is not a regular file");
			return(true);
		}

		ifstream inputFile(localPath.c_str(), std::ios::in | std::ios::binary);
		if (!inputFile.good() )
		{
			respondError(404, "Error while opening " + path );
			return(true);
		}

		//determine content-type
		smatch what;
		if (regex_search(
			path,
			what,
			boost::regex("([^.]*$)")
		))
		{
			string extention=what[1];
			if (config["contentTypes"].isSet(extention))
			{
				extraHeaders["content-type"]=config["contentTypes"][extention];
				DEB("Content type of ." << extention << " is " << config["contentTypes"][extention].str());
			}
			else
			{
				WARNING("Cannot determine content-type of ." << extention << " files");
			}
		}

		//determine filesize
		inputFile.seekg (0, ios::end);
		int fileSize=inputFile.tellg();
		inputFile.seekg (0, ios::beg);
		extraHeaders["Content-Length"]=fileSize;

		//enable browser caching with the right headers:
		extraHeaders["Cache-Control"]="public, max-age=290304000";
		getHttpDate(extraHeaders["Date"].str());

		sendHeaders(200, extraHeaders);



		DEB(id << " sending CONTENT of " << path);
		char buf[4096];
		//TODO: is there a better way to do this?
		int sendSize=0;
		while (inputFile.good())
		{
			inputFile.read(buf	,sizeof(buf));
			if (!sendData(asio::buffer(buf, inputFile.gcount())))
			{
				break;
			}
			sendSize+=inputFile.gcount();
		}

		if (sendSize!=fileSize)
		{
			ERROR(id <<  " error during file transfer, disconnecting");
			doDisconnect();
		}

		return true;
	}
	void QtUdpSocketPlugin::disconnect() {
		emit doDisconnect();
		_messageCounter = 0;
		_helperReceiveCallback = std::function<void(QString)>();
		_checkerReceiveCallback = std::function<void(void)>();
	}
Exemplo n.º 25
0
void ConnectionWindow::connectionClosed()
{
    doDisconnect();
}