Remake
Loading...
Searching...
No Matches
Functions
Client

Functions

static void client_mode (char *socket_name, string_list const &targets)
 

Detailed Description

Function Documentation

◆ client_mode()

static void client_mode ( char * socket_name,
string_list const & targets )
static

Connect to the server socket_name, send a request for building targets with some variables, and exit with the status returned by the server.

Definition at line 2934 of file remake.cpp.

2935{
2936 if (false)
2937 {
2938 error:
2939 perror("Failed to send targets to server");
2941 }
2942 if (targets.empty()) exit(EXIT_SUCCESS);
2943 DEBUG_open << "Connecting to server... ";
2944
2945 // Connect to server.
2946#ifdef WINDOWS
2947 struct sockaddr_in socket_addr;
2948 socket_fd = socket(AF_INET, SOCK_STREAM, 0);
2949 if (socket_fd == INVALID_SOCKET) goto error;
2950 socket_addr.sin_family = AF_INET;
2951 socket_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
2952 socket_addr.sin_port = atoi(socket_name);
2953 if (connect(socket_fd, (struct sockaddr *)&socket_addr, sizeof(sockaddr_in)))
2954 goto error;
2955#else
2956 struct sockaddr_un socket_addr;
2957 size_t len = strlen(socket_name);
2958 if (len >= sizeof(socket_addr.sun_path) - 1) exit(EXIT_FAILURE);
2959 socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
2960 if (socket_fd == INVALID_SOCKET) goto error;
2961 socket_addr.sun_family = AF_UNIX;
2962 strcpy(socket_addr.sun_path, socket_name);
2963 if (connect(socket_fd, (struct sockaddr *)&socket_addr, sizeof(socket_addr.sun_family) + len))
2964 goto error;
2965#ifdef MACOSX
2966 int set_option = 1;
2968 goto error;
2969#endif
2970#endif
2971
2972 // Send current job id.
2973 char *id = getenv("REMAKE_JOB_ID");
2974 int job_id = id ? atoi(id) : -1;
2975 if (send(socket_fd, (char *)&job_id, sizeof(job_id), MSG_NOSIGNAL) != sizeof(job_id))
2976 goto error;
2977
2978 // Send targets.
2979 for (string_list::const_iterator i = targets.begin(),
2980 i_end = targets.end(); i != i_end; ++i)
2981 {
2982 DEBUG_open << "Sending target " << *i << "... ";
2983 std::string s = 'T' + *i;
2984 ssize_t len = s.length() + 1;
2985 if (send(socket_fd, s.c_str(), len, MSG_NOSIGNAL) != len)
2986 goto error;
2987 }
2988
2989 // Send variables.
2990 for (variable_map::const_iterator i = variables.begin(),
2991 i_end = variables.end(); i != i_end; ++i)
2992 {
2993 DEBUG_open << "Sending variable " << i->first << "... ";
2994 std::string s = 'V' + i->first;
2995 ssize_t len = s.length() + 1;
2996 if (send(socket_fd, s.c_str(), len, MSG_NOSIGNAL) != len)
2997 goto error;
2998 for (string_list::const_iterator j = i->second.begin(),
2999 j_end = i->second.end(); j != j_end; ++j)
3000 {
3001 std::string s = 'W' + *j;
3002 len = s.length() + 1;
3003 if (send(socket_fd, s.c_str(), len, MSG_NOSIGNAL) != len)
3004 goto error;
3005 }
3006 }
3007
3008 // Send terminating nul and wait for reply.
3009 char result = 0;
3010 if (send(socket_fd, &result, 1, MSG_NOSIGNAL) != 1) goto error;
3011 if (recv(socket_fd, &result, 1, 0) != 1) exit(EXIT_FAILURE);
3013}
@ INVALID_SOCKET
Definition remake.cpp:463
static variable_map variables
Definition remake.cpp:619
static char * socket_name
Definition remake.cpp:710
#define DEBUG_open
Definition remake.cpp:818
static socket_t socket_fd
Definition remake.cpp:699
ref_ptr()
Definition remake.cpp:491

Referenced by main().