49 #pragma comment(lib, "Ws2_32.lib")
50 #pragma comment(lib, "Mswsock.lib")
51 #pragma comment(lib, "AdvApi32.lib")
54 typedef SSIZE_T ssize_t;
63 namespace Gecode {
namespace CPProfiler {
104 const unsigned int port;
109 static int sendall(
int s,
const char* buf,
int* len);
110 void sendOverSocket(
void);
111 void sendRawMsg(
const std::vector<char>& buf);
122 void start(
const std::string& file_path =
"",
123 int execution_id = -1,
bool has_restarts =
false);
124 void restart(
int restart_id = -1);
142 : node_{node}, parent_{parent},
143 alt_(alt), kids_(kids), status_(status) {}
230 Connector::sendall(
int s,
const char* buf,
int* len) {
232 int bytesleft = *len;
235 while (total < *len) {
236 n = send(s, buf + total, static_cast<size_t>(bytesleft), 0);
240 total += static_cast<int>(
n);
241 bytesleft -= static_cast<int>(
n);
244 *len = static_cast<int>(total);
246 return (
n == -1) ? -1 : 0;
250 Connector::sendRawMsg(
const std::vector<char>& buf) {
251 uint32_t bufSize = static_cast<uint32_t>(buf.size());
252 int bufSizeLen =
sizeof(uint32_t);
253 sendall(sockfd, reinterpret_cast<char*>(&bufSize), &bufSizeLen);
254 int bufSizeInt = static_cast<int>(bufSize);
255 sendall(sockfd, reinterpret_cast<const char*>(buf.data()), &bufSizeInt);
259 Connector::sendOverSocket(
void) {
260 if (!_connected)
return;
262 std::vector<char> buf = marshalling.serialize();
269 struct addrinfo hints, *servinfo, *
p;
275 int startupResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
276 if (startupResult != 0) {
277 printf(
"WSAStartup failed with error: %d\n", startupResult);
281 memset(&hints, 0,
sizeof hints);
282 hints.ai_family = AF_UNSPEC;
283 hints.ai_socktype = SOCK_STREAM;
285 if ((rv = getaddrinfo(
"localhost", std::to_string(port).c_str(), &hints,
287 std::cerr <<
"getaddrinfo: " << gai_strerror(rv) <<
"\n";
292 for (
p = servinfo;
p != NULL;
p =
p->ai_next) {
293 if ((sockfd = static_cast<int>(socket(
p->ai_family,
p->ai_socktype,
p->ai_protocol))) == -1) {
298 if (::
connect(sockfd,
p->ai_addr,
p->ai_addrlen) == -1) {
316 freeaddrinfo(servinfo);
329 int execution_id,
bool has_restarts) {
331 std::string base_name(file_path);
333 size_t pos = base_name.find_last_of(
'/');
334 if (
pos != static_cast<size_t>(-1)) {
335 base_name = base_name.substr(
pos + 1, base_name.length() -
pos - 1);
339 std::string info{
""};
341 std::stringstream ss;
343 ss <<
"\"has_restarts\": " << (has_restarts ?
"true" :
"false") <<
"\n";
344 ss <<
",\"name\": " <<
"\"" << base_name <<
"\"" <<
"\n";
345 if (execution_id != -1) {
346 ss <<
",\"execution_id\": " << execution_id;
359 std::string info{
""};
361 std::stringstream ss;
363 ss <<
"\"restart_id\": " << restart_id <<
"\n";
389 if (!_connected)
return;
404 return Node(node, parent, alt, kids, status);