socklen_t size;
struct sockaddr_un sockaddr;
- sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ sock = socket(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
if (sock < 0) {
_E("[CPU-BOOSTING-PLUGIN] Failed to allocate a socket");
return -1;
return false;
}
- if (pid.pid == 0 && pid.tid != NULL && pid.tid_count <= 0) {
- _E("[CPU-BOOSTING-PLUGIN] tid count should be larger than 0");
- return false;
+ if (pid.pid == 0 && pid.tid != NULL) {
+ if (pid.tid_count <= 0) {
+ _E("[CPU-BOOSTING-PLUGIN] tid count should be larger than 0");
+ return false;
+ }
+
+ for (int i = 0; i < pid.tid_count; i++) {
+ if (pid.tid[i] <= 0) {
+ _E("[CPU-BOOSTING-PLUGIN] Thread (id = %d) should be larger than 0",
+ pid.tid[i]);
+ return false;
+ }
+ }
}
return true;
int ret;
int byte;
int sock;
+ bool retry = false;
cpu_boosting_output_t output;
cpu_boosting_input_t input;
if (ret < 0)
goto close_sock;
+ struct timeval tv;
+ tv.tv_sec = 3;
+ setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv, sizeof(tv));
+
+retry_header:
byte = recv(sock, (void *)&output, sizeof(output), 0);
if (byte != sizeof(output)) {
- char error_buf[1024];
- strerror_r(errno, error_buf, sizeof(error_buf));
+ if (byte < 0) {
+ if (errno == EAGAIN && retry == false) {
+ retry = true;
+ sleep(1);
+ goto retry_header;
+ }
- _E("[CPU-BOOSTING-PLUGIN] error is based on %s", error_buf);
- _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
- (unsigned int)sizeof(output), byte);
+ char error_buf[1024];
+ strerror_r(errno, error_buf, sizeof(error_buf));
+ _E("[CPU-BOOSTING-PLUGIN] error is based on %s", error_buf);
+ }
+ else
+ _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
+ (unsigned int)sizeof(output), byte);
ret = -1;
goto close_sock;
}
else
level->tid_count = output.level.tid_count;
+retry_body:
byte = recv(sock, (void *)level->tid_level, level->tid_count * sizeof(int), 0);
if (byte != level->tid_count * sizeof(int)) {
- char error_buf[1024];
- strerror_r(errno, error_buf, sizeof(error_buf));
+ if (byte < 0) {
+ if (errno == EAGAIN && retry == false) {
+ retry = true;
+ sleep(1);
+ goto retry_body;
+ }
+
+ char error_buf[1024];
+ strerror_r(errno, error_buf, sizeof(error_buf));
+ _E("[CPU-BOOSTING-PLUGIN] error is based on %s", error_buf);
+ }
+ else
+ _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
+ level->tid_count * (unsigned int)sizeof(int), byte);
- _E("[CPU-BOOSTING-PLUGIN] error is based on %s", error_buf);
- _E("[CPU-BOOSTING-PLUGIN] client output size is %u, but received size is %d",
- level->tid_count * (unsigned int)sizeof(int), byte);
free(level->tid_level);
ret = -1;
goto close_sock;