53 #pragma comment(lib, "Ws2_32.lib") 54 #pragma comment(lib, "Mswsock.lib") 55 #pragma comment(lib, "AdvApi32.lib") 58 typedef SSIZE_T ssize_t;
67 namespace Gecode {
namespace CPProfiler {
108 const unsigned int port;
113 static int sendall(
int s,
const char* buf,
int* len);
114 void sendOverSocket(
void);
115 void sendRawMsg(
const std::vector<char>& buf);
119 bool connected()
const;
126 void start(
const std::string& file_path =
"",
127 int execution_id = -1,
bool has_restarts =
false);
128 void restart(
int restart_id = -1);
132 void disconnect(
void);
134 void sendNode(
const Node& node);
146 : node_{node}, parent_{parent},
234 Connector::sendall(
int s,
const char* buf,
int* len) {
236 int bytesleft = *len;
239 while (total < *len) {
240 n = send(s, buf + total, static_cast<size_t>(bytesleft), 0);
250 return n == -1 ? -1 : 0;
254 Connector::sendRawMsg(
const std::vector<char>& buf) {
255 uint32_t bufSize =
static_cast<uint32_t
>(buf.size());
256 int bufSizeLen =
sizeof(uint32_t);
257 sendall(sockfd, reinterpret_cast<char*>(&bufSize), &bufSizeLen);
258 int bufSizeInt =
static_cast<int>(bufSize);
259 sendall(sockfd, reinterpret_cast<const char*>(buf.data()), &bufSizeInt);
263 Connector::sendOverSocket(
void) {
264 if (!_connected)
return;
266 std::vector<char> buf = marshalling.serialize();
273 struct addrinfo hints, *servinfo, *
p;
279 int startupResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
280 if (startupResult != 0) {
281 printf(
"WSAStartup failed with error: %d\n", startupResult);
285 memset(&hints, 0,
sizeof hints);
286 hints.ai_family = AF_UNSPEC;
287 hints.ai_socktype = SOCK_STREAM;
289 if ((rv = getaddrinfo(
"localhost", std::to_string(port).c_str(), &hints,
291 std::cerr <<
"getaddrinfo: " << gai_strerror(rv) <<
"\n";
296 for (p = servinfo; p != NULL; p = p->ai_next) {
297 if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
302 if (::
connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
320 freeaddrinfo(servinfo);
333 int execution_id,
bool has_restarts) {
335 std::string base_name(file_path);
337 size_t pos = base_name.find_last_of(
'/');
338 if (pos != static_cast<size_t>(-1)) {
339 base_name = base_name.substr(pos + 1, base_name.length() - pos - 1);
343 std::string info{
""};
345 std::stringstream ss;
347 ss <<
"\"has_restarts\": " << (has_restarts ?
"true" :
"false") <<
"\n";
348 ss <<
",\"name\": " <<
"\"" << base_name <<
"\"" <<
"\n";
349 if (execution_id != -1) {
350 ss <<
",\"execution_id\": " << execution_id;
363 std::string info{
""};
365 std::stringstream ss;
367 ss <<
"\"restart_id\": " << restart_id <<
"\n";
393 if (!_connected)
return;
408 return Node(node, parent, alt, kids, status);
int node_restart_id() const
const Option< std::string > & nogood() const
void disconnect(void)
disconnect from a socket
Node & set_info(const std::string &info)
int parent_thread_id() const
NodeStatus status() const
bool pos(const View &x)
Test whether x is postive.
void connect(void)
connect to a socket via port specified in the construction (6565 by default)
Node & set_nogood(const std::string &nogood)
int node_thread_id() const
const Option< std::string > & label() const
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Node createNode(NodeUID node, NodeUID parent, int alt, int kids, NodeStatus status)
void makeStart(const std::string &info)
void set(const T &t)
Set value to t.
int parent_restart_id() const
void start(const std::string &file_path="", int execution_id=-1, bool has_restarts=false)
Connector(unsigned int port)
Node(NodeUID node, NodeUID parent, int alt, int kids, NodeStatus status)
Node & set_node_thread_id(int tid)
bool valid(void) const
Check whether value is present.
Message & makeNode(NodeUID node, NodeUID parent, int32_t alt, int32_t kids, NodeStatus status)
const Option< std::string > & info() const
void makeRestart(const std::string &info)
void set_label(const std::string &label)
Gecode toplevel namespace
Node & set_label(const std::string &label)
NodeUID parentUID() const
NodeStatus
Types of nodes for CP Profiler.
const T & value(void) const
Access value.
void restart(int restart_id=-1)
void sendNode(const Node &node)
Unique identifier for a node.