diff options
author | fcolin | 2009-10-08 13:07:04 +0000 |
---|---|---|
committer | fcolin | 2009-10-08 13:07:04 +0000 |
commit | 00e97f3decde46e85fba871a20aa79e27cb679e3 (patch) | |
tree | 31084ff19777b8cbe36b1eeb9d979370a33f79d7 /Ivy/IvyApplication.cxx | |
parent | 773d105e88a4323b844b378e599e2884310eaa50 (diff) | |
download | ivy-cplusplus-00e97f3decde46e85fba871a20aa79e27cb679e3.zip ivy-cplusplus-00e97f3decde46e85fba871a20aa79e27cb679e3.tar.gz ivy-cplusplus-00e97f3decde46e85fba871a20aa79e27cb679e3.tar.bz2 ivy-cplusplus-00e97f3decde46e85fba871a20aa79e27cb679e3.tar.xz |
correction des bug connexion concurrente
correction sur le ready message attente des deux endRegexp
Diffstat (limited to 'Ivy/IvyApplication.cxx')
-rw-r--r-- | Ivy/IvyApplication.cxx | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/Ivy/IvyApplication.cxx b/Ivy/IvyApplication.cxx index a262fa2..4b41bbe 100644 --- a/Ivy/IvyApplication.cxx +++ b/Ivy/IvyApplication.cxx @@ -12,6 +12,9 @@ #define ARG_START 2
#define ARG_END 3
+#define MAXPORT(a,b) ((a>b) ? a : b)
+
+
static char * firstArg( char *s, const char separator )
{
char *ptr = s;
@@ -46,6 +49,8 @@ IvyApplication::IvyApplication(Ivy * bus) remoteService = 0; /* unknown or unconnected application */
appname = "Unknown";
AppConnectedCallbackCalled = false;
+ readyToSend = 0;
+ InitializeCriticalSection(&m_SendReadySection );
}
IvyApplication::~IvyApplication()
@@ -56,6 +61,9 @@ IvyApplication::~IvyApplication() regexp_in.clear();
if ( m_hSocket != INVALID_SOCKET )
Close();
+ // Release resources used by the critical section object.
+ DeleteCriticalSection(&m_SendReadySection);
+
}
@@ -87,7 +95,14 @@ UINT IvyApplication::Create() #endif
return port;
}
-
+void IvyApplication::SendReadyToPeer()
+{
+ EnterCriticalSection (&m_SendReadySection);
+ readyToSend++;
+ if ( !bus->ready_message.empty() && readyToSend == 2 )
+ SendMsg( bus->ready_message.c_str() );
+ LeaveCriticalSection (&m_SendReadySection);
+}
void IvyApplication::OnReceive(char * line)
{
int err;
@@ -191,7 +206,7 @@ void IvyApplication::OnReceive(char * line) }
break;
case StartRegexp:
-
+ {
#ifdef IVY_DEBUG
TRACE("Regexp Start id=%d\n", id);
#endif //IVY_DEBUG
@@ -199,12 +214,29 @@ void IvyApplication::OnReceive(char * line) appname = arg;
/* remote socket port */
remoteService = id;
- if ( bus->CheckConnected( this ) )
+ IvyApplication *other = bus->CheckConnected( this );
+ if ( other )
{
- TRACE("Quitting already connected %s\n", appname.c_str());
- SendMsg( Error, Error, "already connected" );
-// bus->RemoveApplication( this );
- Close();
+ // Dilemma choose the rigth client to close
+ // the symetric processing will try to close each other
+ // only one side may be closed
+ IvyApplication *target;
+ if (MAXPORT(other->GetLocalPort(), other->GetRemotePort()) > MAXPORT( this->GetLocalPort(), this->GetRemotePort() ))
+ {
+ target = other;
+ TRACE("choose %s other ports %d,%d\n", appname.c_str(), target->GetLocalPort(), target->GetRemotePort());
+ }
+ else
+ {
+ target = this;
+ TRACE("choose %s this ports %d,%d\n", appname.c_str(), target->GetRemotePort(), target->GetLocalPort());
+ }
+
+ TRACE("Quitting already connected %s\n", appname.c_str());
+ target->SendMsg( Error, Error, "already connected" );
+ // bus->RemoveApplication( target );
+ target->Close();
+ }
}
break;
case EndRegexp:
@@ -215,8 +247,7 @@ void IvyApplication::OnReceive(char * line) bus->CallApplicationConnectedCallback( this );
AppConnectedCallbackCalled = true;
- if ( !bus->ready_message.empty() )
- SendMsg( bus->ready_message.c_str() );
+ SendReadyToPeer();
break;
case Msg:
|