summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsc2000-11-29 12:48:27 +0000
committersc2000-11-29 12:48:27 +0000
commit1fb2dd2c5aa49578bb5a6fcbaaa04460be6728ad (patch)
tree527b5dd644bf914e2c7df9e4d082163283d75706
parent4a8e1c0e43f7c70d84d1f0b850e66a32c00a47b8 (diff)
downloadivy-league-1fb2dd2c5aa49578bb5a6fcbaaa04460be6728ad.zip
ivy-league-1fb2dd2c5aa49578bb5a6fcbaaa04460be6728ad.tar.gz
ivy-league-1fb2dd2c5aa49578bb5a6fcbaaa04460be6728ad.tar.bz2
ivy-league-1fb2dd2c5aa49578bb5a6fcbaaa04460be6728ad.tar.xz
Changed name of event classes
Improved error messages Fixed bug in emission of port number in the broadcast message, which implied changes in the handling of addresses (host and net reprs)
-rw-r--r--comm/BusAccess.cc72
1 files changed, 40 insertions, 32 deletions
diff --git a/comm/BusAccess.cc b/comm/BusAccess.cc
index 3f9605a..f043fd2 100644
--- a/comm/BusAccess.cc
+++ b/comm/BusAccess.cc
@@ -95,7 +95,7 @@ IvlBusSubscription :: IvlBusSubscription (int id, const char* r)
{
int reg = regcomp (&Compiled, r, REG_ICASE|REG_EXTENDED);
if (reg != 0)
- cerr << "bad regexp " << r << "\n";
+ cerr << "Ivy warning: bad regexp " << r << "\n";
}
IvlBusServer :: IvlBusServer (IvlBusAccess* bus)
@@ -103,7 +103,7 @@ IvlBusServer :: IvlBusServer (IvlBusAccess* bus)
MyBus (bus)
{
if (Listen () < 0) {
- cerr << "cannot listen on bus server\n";
+ perror ("Ivy warning. Cannot listen on bus server");
return;
}
SetMode (IORead);
@@ -117,7 +117,7 @@ IvlBusServer :: HandleRead ()
/* Accept connection */
int fd = Accept ();
if (fd < 0) {
- cerr << "cannot accept connection on server\n";
+ perror ("Ivy warning. Cannot accept connection on server");
return;
}
@@ -136,21 +136,21 @@ IvlBusAgent :: IvlBusAgent (int fd, IvlBusAccess* bus)
MyBus (bus),
DirectMsg (16)
{
-// SetMode (IOReadWrite);
SetMode (IORead);
IvlChannel::Open (fd);
Add (IvlScd);
MyBus->Agents.Append (this);
}
-IvlBusAgent :: IvlBusAgent (const char* host, sword port, IvlBusAccess *bus)
+IvlBusAgent :: IvlBusAgent (lword host, sword port, IvlBusAccess *bus)
: IvlBufStream (0, new IvlInetAddress (host, port)),
RemoteSubscriptions (),
MyBus (bus),
DirectMsg (16)
{
if (!Setup ()) {
- cerr << "cannot set up stream on " << host << ":" << port << "\n";
+ cerr << "Ivy warning. Cannot set up stream on";
+ perror ("");
return;
}
SetMode (IORead);
@@ -278,7 +278,7 @@ IvlBusAgent :: ProcessLine (const char* line)
int msg_type, id, nb_chars;
int nb_fields = sscanf (line,"%d %d%n", &msg_type, &id, &nb_chars);
if (nb_fields != 2) {
- cerr << "Bad format: " << line;
+ cerr << "Ivy warning: bad message format: " << line;
return;
}
@@ -288,7 +288,7 @@ IvlBusAgent :: ProcessLine (const char* line)
case BusBye:
if (_BusDebug)
cout << "[bye " << Name << "]\n";
- ev = new IvlAgentEvent (this, IvlAgentEvent::BusAgentBye);
+ ev = new IvlBusAgentEvent (this, IvlBusAgentEvent::BusAgentBye);
Bye.Dispatch (*ev);
delete this;
break;
@@ -311,7 +311,7 @@ IvlBusAgent :: ProcessLine (const char* line)
case BusReady:
if (_BusDebug)
cout << "[ready " << Name << "]\n";
- ev = new IvlAgentEvent (this, IvlAgentEvent::BusNewAgent);
+ ev = new IvlBusAgentEvent (this, IvlBusAgentEvent::BusNewAgent);
MyBus->NewAgents.Dispatch (*ev);
break;
case BusDirectMsg:
@@ -439,30 +439,31 @@ IvlBusAccess :: IvlBusAccess (const char* name, const char* bus)
IvlInetAddress* a = new IvlInetAddress (ANYADDR, BroadcastPort);
BindTo (a);
if (!Open ()) {
- perror ("Cannot open socket: ");
+ perror ("Ivy warning. Cannot open socket");
return;
}
if (!AllowBroadcast ()) {
- perror ("socket won't broadcast: ");
+ perror ("Ivy warning. Socket won't broadcast");
return;
}
if (!ReuseAddress ()) {
- perror ("socket won't let address be reused: ");
+ perror ("Ivy warning. Socket won't let address be reused");
return;
}
if (Bind () < 0) {
- cerr << "cannot bind socket to port " << BroadcastPort << "\n";
+ cerr << "Ivy warning. Cannot bind socket to port " << BroadcastPort;
+ perror ("");
return;
}
-// SetMode (IOReadWrite);
+
SetMode (IORead);
/** set up stream **/
Server = new IvlBusServer (this);
a = dynamic_cast<IvlInetAddress*>(Server->BoundTo ());
if (!a) {
- cerr << "bad address type?!\n";
+ cerr << "Ivy warning: bad address type?!\n";
return;
}
ListenPort = a->Port ();
@@ -488,7 +489,7 @@ IvlBusAccess :: IvlBusAccess (const char* name, const char* bus)
/* address elements are up to 3 digits... */
if (!error && isdigit (*bus)) {
if (numdigit < 3 && numelem < 4) {
- elem = 10 * elem + *bus -'0';
+ elem = 10 * elem + *bus - '0';
} else {
error = 1;
}
@@ -505,7 +506,12 @@ IvlBusAccess :: IvlBusAccess (const char* name, const char* bus)
} else {
printf ("Broadcasting on network %lx, port %d\n", mask, BroadcastPort);
IvlInetAddress ba (mask, BroadcastPort);
- Send ((byte*)handshake, strlen (handshake), ba);
+ if (Send ((byte*)handshake, strlen (handshake), ba) < 0) {
+ cerr << "Ivy warning. Broadcast to 0x"
+ << hex (mask) << ":"
+ << BroadcastPort;
+ perror (" failed");
+ }
numelem = 0;
mask = 0xffffffff;
}
@@ -514,7 +520,7 @@ IvlBusAccess :: IvlBusAccess (const char* name, const char* bus)
/* recover from bad addresses at next comma or colon or at end of string */
} else if (*bus == ',' || *bus == ':' || *bus == '\0') {
- fprintf (stderr, "bad broadcast address\n");
+ cerr << "Ivy warning: bad broadcast address\n";
elem = 0;
numelem = 0;
numdigit = 0;
@@ -564,7 +570,7 @@ IvlBusAccess :: HandleRead ()
byte buf [256];
int nb_bytes = Receive (buf, 256);
if (nb_bytes < 0) {
- cerr << "read error on broadcast port\n";
+ perror ("Ivy warning. Read error on broadcast port");
return;
}
@@ -573,32 +579,34 @@ IvlBusAccess :: HandleRead ()
sword remote_listen_port;
int nb_infos = sscanf ((char*) buf, "%d %hu", &bus_version, &remote_listen_port);
if (nb_infos < 2) {
- cerr << "bad data on broadcast port\n";
+ cerr << "Ivy warning: bad data on broadcast port\n";
return;
}
/* where did this come from? */
IvlInetAddress* a = dynamic_cast<IvlInetAddress*> (From ());
- if (!a) {
- cerr << "bad address!?\n";
+ if (!a) {
+ cerr << "Ivy warning: bad address!?\n";
return;
}
- const char* remote_host = a->GetHostName ();
- sword remote_port = a->Port ();
/* sanity checks: is it the same protocol version? is it myself calling? */
if (remote_listen_port == ListenPort)
return;
if (bus_version != Version) {
- cerr << "bad protocol version\n";
+ cerr << "Ivy warning: bad protocol version\n";
return;
}
- if (_BusDebug)
+ if (_BusDebug) {
+ const char* remote_host = a->GetHostName ();
+ sword remote_port = a->Port ();
printf ("Arrivee de %s:%hu port %hu\n", remote_host, remote_port, remote_listen_port );
+ }
/* Create agent handle */
- IvlBusAgent* ag = new IvlBusAgent (remote_host, remote_listen_port, this);
+// IvlBusAgent* ag = new IvlBusAgent (remote_host, remote_listen_port, this);
+ IvlBusAgent* ag = new IvlBusAgent (a->Host (), remote_listen_port, this);
/* send name and subscriptions */
ag->SayHello ();
@@ -609,7 +617,7 @@ IvlBusAccess :: HandleEvent (int id, const char* msg)
{
IvlBusTrigger* s = IdToSubscription.Get (id);
if (!s) {
- cerr << "bad regexp id " << id << "\n";
+ cerr << "Ivy warning: bad regexp id " << id << "\n";
return;
}
@@ -682,8 +690,8 @@ IvlBusAccess :: Emit (const char* fmt, ...)
}
-IvlEventType* IvlAgentEvent::BusNewAgent = new IvlEventType ("new agent", 0, 0);
-IvlEventType* IvlAgentEvent::BusAgentBye = new IvlEventType ("agent bye", 0, 0);
+IvlEventType* IvlBusAgentEvent::BusNewAgent = new IvlEventType ("new agent", 0, 0);
+IvlEventType* IvlBusAgentEvent::BusAgentBye = new IvlEventType ("agent bye", 0, 0);
IvlBusEvent :: IvlBusEvent (const char* r, const char* m)
: IvlEvent (),
@@ -721,13 +729,13 @@ IvlBusEvent :: ~IvlBusEvent ()
delete (*li);
}
-IvlAgentEvent :: IvlAgentEvent (IvlBusAgent* a, IvlEventType* t)
+IvlBusAgentEvent :: IvlBusAgentEvent (IvlBusAgent* a, IvlEventType* t)
: IvlEvent (t),
Agent (a)
{
}
-IvlAgentEvent :: ~IvlAgentEvent ()
+IvlBusAgentEvent :: ~IvlBusAgentEvent ()
{
}