status_t 
AbstractReflectSession ::
AddOutgoingMessage(const MessageRef & ref) 
{
   MASSERT(IsAttachedToServer(), "Can not call AddOutgoingMessage() while not attached to the server");
   return (_gateway()) ? _gateway()->AddOutgoingMessage(ref) : B_ERROR;
}
bool
AbstractReflectSession ::
DisconnectSession()
{
   MASSERT(IsAttachedToServer(), "Can not call DisconnectSession() while not attached to the server");
   return GetOwner()->DisconnectSession(this);
}
status_t
AbstractReflectSession ::
ReplaceSession(const AbstractReflectSessionRef & replaceMeWithThis)
{
   MASSERT(IsAttachedToServer(), "Can not call ReplaceSession() while not attached to the server");
   return GetOwner()->ReplaceSession(replaceMeWithThis, this);
}
const IPAddress &
AbstractReflectSession ::
GetLocalInterfaceAddress() const 
{
   MASSERT(IsAttachedToServer(), "Can not call LocalInterfaceAddress() while not attached to the server");
   return _ipAddressAndPort.GetIPAddress();
}
uint16
AbstractReflectSession ::
GetPort() const 
{
   MASSERT(IsAttachedToServer(), "Can not call GetPort() while not attached to the server");
   return _ipAddressAndPort.GetPort();
}
const String &
AbstractReflectSession ::
GetHostName() const 
{
   MASSERT(IsAttachedToServer(), "Can not call GetHostName() while not attached to the server");
   return _hostName;
}
Example #7
0
void SignalHandlerSession :: SignalHandlerFunc(int sigNum)
{
   // Note that this method is called within the context of the POSIX/Win32 signal handler and thus we have to
   // be very careful about what we do here!   Sending a byte on a socket should be okay though.  (there is the
   // worry that the SignalHandlerSession object might have been deleted by the time we get here, but I don't
   // think there is much I can do about that)
   if (IsAttachedToServer())
   {
      int nextSigNum;
      for (uint32 i=0; GetNthSignalNumber(i, nextSigNum) == B_NO_ERROR; i++)
      {
         if (sigNum == nextSigNum)
         {
            _wasSignalCaught = true;
            char c = (char) sigNum;
            (void) SendData(_handlerSocket, &c, 1, false);  // send the signal value to the main thread so it can handle it later
            break;
         }
      }
   }
}
void
AbstractReflectSession ::
EndSession()
{
   if (IsAttachedToServer()) GetOwner()->EndSession(this);
}
status_t
AbstractReflectSession ::
Reconnect()
{
   TCHECKPOINT;

#ifdef MUSCLE_ENABLE_SSL
   ConstByteBufferRef publicKey;  // If it's an SSL connection we'll grab its key into here so we can reuse it
#endif

   MASSERT(IsAttachedToServer(), "Can not call Reconnect() while not attached to the server");
   if (_gateway())
   {
#ifdef MUSCLE_ENABLE_SSL
      SSLSocketDataIO * sdio = dynamic_cast<SSLSocketDataIO *>(_gateway()->GetDataIO()());
      if (sdio) publicKey = sdio->GetPublicKeyCertificate();
#endif
      _gateway()->SetDataIO(DataIORef());  // get rid of any existing socket first
      _gateway()->Reset();                 // set gateway back to its virgin state
   }

   _isConnected = _wasConnected = false;
   SetConnectingAsync(false);

   bool doTCPConnect = ((_reconnectViaTCP)&&(_asyncConnectDest.GetIPAddress() != invalidIP));
   bool isReady = false;
   ConstSocketRef sock = doTCPConnect ? ConnectAsync(_asyncConnectDest.GetIPAddress(), _asyncConnectDest.GetPort(), isReady) : CreateDefaultSocket();

   // FogBugz #5256:  If ConnectAsync() fails, we want to act as if it succeeded, so that the calling
   //                 code still uses its normal asynchronous-connect-failure code path.  That way the
   //                 caller doesn't have to worry about synchronous failure as a separate case.
   if ((doTCPConnect)&&(sock() == NULL))
   {
      ConstSocketRef tempSockRef;  // tempSockRef represents the closed remote end of the failed connection and is intentionally closed ASAP
      if (CreateConnectedSocketPair(sock, tempSockRef) == B_NO_ERROR) doTCPConnect = false;
   }

   if (sock())
   {
      DataIORef io = CreateDataIO(sock);
      if (io())
      {
         if (_gateway() == NULL)
         {
            _gateway = CreateGateway();
            if (_gateway() == NULL) return B_ERROR;
         }

#ifdef MUSCLE_ENABLE_SSL
         // auto-wrap the user's gateway and socket in the necessary SSL adapters!
         if ((publicKey())&&(dynamic_cast<TCPSocketDataIO *>(io()) != NULL))
         {
            SSLSocketDataIO * ssio = newnothrow SSLSocketDataIO(sock, false, false);
            if (ssio == NULL) {WARN_OUT_OF_MEMORY; return B_ERROR;}
            io.SetRef(ssio);
            if (ssio->SetPublicKeyCertificate(publicKey) != B_NO_ERROR) return B_ERROR;

            if (dynamic_cast<SSLSocketAdapterGateway *>(_gateway()) == NULL) 
            {
               _gateway.SetRef(newnothrow SSLSocketAdapterGateway(_gateway));
               if (_gateway() == NULL) return B_ERROR;
            }
         }
#endif

         _gateway()->SetDataIO(io);
         if (isReady) 
         {
            _isConnected = _wasConnected = true;
            AsyncConnectCompleted();
         }
         else 
         {
            _isConnected = false;
            SetConnectingAsync(doTCPConnect);
         }
         _scratchReconnected = true;   // tells ReflectServer not to shut down our new IO!
         return B_NO_ERROR;
      }
   }
   return B_ERROR;
}