Changeset 8862 for trunk/MagicSoft/Cosy/tcpip
- Timestamp:
- 02/13/08 19:44:39 (17 years ago)
- Location:
- trunk/MagicSoft/Cosy/tcpip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
r8856 r8862 48 48 49 49 public: 50 MCeCoCom( MLog *out)51 : MTcpIpIO( "ceco", 7304, 7404), fOut(out), fStatus(0), fComStat(kNoCmdReceived),50 MCeCoCom(const char *addr, MLog *out) 51 : MTcpIpIO(addr, 7304, 7404), fOut(out), fStatus(0), fComStat(kNoCmdReceived), 52 52 fHumidity(0), fTemperature(0), fWindSpeed(0), fSolarRadiation(-1), 53 53 fAlarmCounter(0) -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
r8816 r8862 41 41 }; 42 42 43 MDriveCom(MsgQueue *q, MLog *out) : MCeCoCom(out), fQueue(q) {}43 MDriveCom(MsgQueue *q, const char *addr, MLog *out) : MCeCoCom(addr, out), fQueue(q) {} 44 44 45 45 bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er); -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r8856 r8862 8 8 #include "MLog.h" 9 9 #include "MLogManip.h" 10 11 #include "MString.h" 10 12 11 13 #undef DEBUG … … 55 57 } 56 58 59 TString MTcpIpO::GetSocketAddress(const TSocket &s) 60 { 61 if (!s.IsValid()) 62 return "n/a"; 63 64 const TInetAddress &a = s.GetInetAddress(); 65 if (!a.IsValid()) 66 return "undefined"; 67 68 return MString::Format("%s:%d", a.GetHostAddress(), a.GetPort()); 69 } 70 71 TString MTcpIpO::GetSocketAddress() const 72 { 73 return GetSocketAddress(*fTxSocket); 74 } 75 57 76 bool MTcpIpO::SendFrame(TSocket &tx, const char *msg, int len) 58 77 { 59 78 if (!tx.IsValid()) 60 79 { 61 // cout << "*!* Transmit socket invalid!" << endl;80 //gLog << warn << "WARNING - No transmission to " << GetSocketAddress(tx) << " possible." << endl; 62 81 return false; 63 82 } … … 66 85 if (l<0) 67 86 { 68 cout << "ERROR - Sending Message"<< endl;87 gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl; 69 88 return false; 70 89 } … … 72 91 if (l!=len) 73 92 { 74 cout << "Send wrong number (" << l << ") of Bytes."<< endl;93 gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl; 75 94 return false; 76 95 } … … 86 105 { 87 106 // R__LOCKGUARD2(myMutex); 88 107 #ifdef DEBUG 89 108 cout << "Connecting to " << addr << ":" << port << endl; 109 #endif 90 110 91 111 // FIXME: Set tx-socket to nonblocking? 92 112 TSocket tx(addr, port); 93 //return SendFrame(tx, msg, len);94 113 return SendFrame(tx, msg, len); 114 /* 95 115 if (!tx.IsValid()) 96 116 { 97 //cout << "*!* Transmit socket invalid!" << endl;98 return false; 99 } 100 101 cout<< "Sending to " << addr << ":" << port << endl;117 gLog << warn << "WARNING - No transmission to " << addr << ":" << port << " possible." << endl; 118 return false; 119 } 120 121 gLog << dbg << "Sending to " << addr << ":" << port << endl; 102 122 103 123 const Int_t l = tx.SendRaw(msg, len, kDontBlock); 104 124 if (l<0) 105 125 { 106 cout << "ERROR - Sending Message"<< endl;126 gLog << err << "ERROR - Sending TCP/IP frame to " << addr << ":" << port << endl; 107 127 return false; 108 128 } … … 110 130 if (l!=len) 111 131 { 112 cout << "Send wrong number (" << l << ") of Bytes."<< endl;132 gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << addr << ":" << port << endl; 113 133 return false; 114 134 } … … 119 139 120 140 return true; 141 */ 121 142 } 122 143 … … 188 209 gLog << inf << "- Starting receiver on port " << fPortRx << "..." << endl; 189 210 211 // if (fPortRx==7404) 212 // { 213 // gLog << err << "CeCo communication skipped." << endl; 214 // return 0; 215 // } 216 190 217 TServerSocket *fServSock=NULL; 191 218 TSocket *fRxSocket=NULL; … … 197 224 if (!fServSock->IsValid()) 198 225 { 199 cout<< "ServerSocket on port " << fPortRx << " invalid: ";226 gLog << err << "ServerSocket on port " << fPortRx << " invalid: "; 200 227 switch (fServSock->GetErrorCode()) 201 228 { 202 case 0: cout<< "No error." << endl; break;203 case -1: cout<< "low level socket() call failed." << endl; break;204 case -2: cout<< "low level bind() call failed." << endl; break;205 case -3: cout<< "low level listen() call failed." << endl; break;206 default: cout<< "Unknown." << endl; break;229 case 0: gLog << "No error." << endl; break; 230 case -1: gLog << "low level socket() call failed." << endl; break; 231 case -2: gLog << "low level bind() call failed." << endl; break; 232 case -3: gLog << "low level listen() call failed." << endl; break; 233 default: gLog << "Unknown." << endl; break; 207 234 } 208 235 delete fServSock; … … 214 241 fServSock->SetOption(kNoBlock, 1); 215 242 216 cout<< "Waiting for connection on port " << fPortRx << "..." << endl;243 gLog << all << "Waiting for connection on port " << fPortRx << "..." << endl; 217 244 // while (!HasStopFlag() && (Long_t)fRxSocket<=0) 218 245 while (!IsThreadCanceled() && (Long_t)fRxSocket<=0) … … 247 274 } 248 275 249 cout<< "Connection established on port " << fPortRx << "." << endl;276 gLog << all << "Connection established on port " << fPortRx << "." << endl; 250 277 251 278 fRxSocket->SetOption(kNoBlock, 1); -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
r8856 r8862 40 40 ~MTcpIpO(); 41 41 42 static bool SendFrame(TSocket &tx, const char *msg, int len); 43 static bool SendFrame(const char *addr, int port, const char *msg, int len); 42 static TString GetSocketAddress(const TSocket &s); 43 static bool SendFrame(TSocket &tx, const char *msg, int len); 44 static bool SendFrame(const char *addr, int port, const char *msg, int len); 44 45 45 bool Send(const char *msg, int len); 46 TString GetSocketAddress() const; 47 bool Send(const char *msg, int len); 46 48 }; 47 49
Note:
See TracChangeset
for help on using the changeset viewer.