1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Alessandro Tasora
13 // =============================================================================
14 
15 #ifndef CHEXCEPTIONSOCKET_H
16 #define CHEXCEPTIONSOCKET_H
17 
18 #include <fstream>
19 #include <iostream>
20 #include <string>
21 #include <ctime>
22 
23 #include "chrono/core/ChException.h"
24 #include "chrono/core/ChLog.h"
25 #include "chrono_cosimulation/ChApiCosimulation.h"
26 
27 namespace chrono {
28 namespace cosimul {
29 
30 /// Class for exceptions that are thrown by TCP socket connections,
31 /// used for example when connecting with other sw for cosimulation.
32 
33 class ChExceptionSocket : public ChException {
34   public:
ChExceptionSocket(int code,const std::string & what)35     ChExceptionSocket(int code, const std::string& what) : ChException(what), errorCode(code){};
36 
37     // get socket error code in thrown exception
getErrCode()38     int getErrCode() { return errorCode; }
39 
40     // std::string& getErrMsg() { return std::string(this->what()); }
41 
response()42     void response() {
43         GetLog() << "TCP socket error: \n";
44         GetLog() << "		==> error code: " << errorCode << "\n";
45         GetLog() << "		==> error message: " << this->what() << "\n";
46     }
47 
48   private:
49     int errorCode;
50 };
51 
52 }  // end namespace cosimul
53 }  // end namespace chrono
54 
55 #endif