static GDBusConnection *_gdbus_conn = NULL;
+/* 100 milliseconds */
+const struct timespec TRY_SLEEP_TIME = { 0, 100 * 1000 * 1000 };
+
int __datacontrol_get_provider_id(void)
{
static int id = 0;
*bytes_write = 0;
while (left && (retry_cnt < MAX_RETRY)) {
nb = write(fd, buffer, left);
- _LOGI("_write_socket: ...from %d: nb %d left %d\n", fd, nb, left - nb);
+ _LOGD("from %d: nb %d left %d", fd, nb, left - nb);
if (nb == -1) {
- if (errno == EINTR) {
- _LOGE("_write_socket: EINTR error continue ...");
+ if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
+ _LOGE("%d error continue", errno);
retry_cnt++;
+ nanosleep(&TRY_SLEEP_TIME, 0);
continue;
}
- _LOGE("_write_socket: ...error fd %d: errno %d\n", fd, errno);
+ _LOGE("error fd %d: errno %d", fd, errno);
return DATA_CONTROL_ERROR_IO_ERROR;
}
retry_cnt = 0;
}
+ if (left != 0) {
+ _LOGE("error fd %d: retry_cnt %d", fd, retry_cnt);
+ return DATA_CONTROL_ERROR_IO_ERROR;
+ }
+
return DATA_CONTROL_ERROR_NONE;
}
unsigned int left = nbytes;
gsize nb;
int retry_cnt = 0;
- const struct timespec TRY_SLEEP_TIME = { 0, 500 * 1000 * 1000 };
*bytes_read = 0;
while (left && (retry_cnt < MAX_RETRY)) {
nb = read(fd, buffer, left);
- _LOGI("_read_socket: ...from %d: nb %d left %d\n", fd, nb, left - nb);
+ _LOGD("from %d: nb %d left %d", fd, nb, left - nb);
if (nb == 0) {
- _LOGE("_read_socket: ...read EOF, socket closed %d: nb %d\n", fd, nb);
+ _LOGE("read EOF, socket closed %d: nb %d errno %d", fd, nb, errno);
return DATA_CONTROL_ERROR_IO_ERROR;
} else if (nb == -1) {
- /* wrt(nodejs) could change socket to none-blocking socket :-( */
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
- _LOGE("_read_socket: %d errno, sleep and retry ...", errno);
+ _LOGE("%d errno, sleep and retry", errno);
retry_cnt++;
nanosleep(&TRY_SLEEP_TIME, 0);
continue;
}
- _LOGE("_read_socket: ...error fd %d: errno %d\n", fd, errno);
+ _LOGE("error fd %d: errno %d", fd, errno);
return DATA_CONTROL_ERROR_IO_ERROR;
}
*bytes_read += nb;
retry_cnt = 0;
}
+
+ if (left != 0) {
+ _LOGE("error fd %d: retry_cnt %d", fd, retry_cnt);
+ return DATA_CONTROL_ERROR_IO_ERROR;
+ }
return DATA_CONTROL_ERROR_NONE;
}
#define _LOGE(fmt, arg...) LOGE(fmt, ##arg)
#define _LOGI(fmt, arg...) LOGI(fmt, ##arg)
+#define _LOGD(fmt, arg...) LOGD(fmt, ##arg)
#define _SECURE_LOGE(fmt, arg...) SECURE_LOGE(fmt, ##arg)
#define _SECURE_LOGI(fmt, arg...) SECURE_LOGI(fmt, ##arg)
+#define _SECURE_LOGD(fmt, arg...) SECURE_LOGD(fmt, ##arg)
#endif /* __TIZEN_APPFW_DATA_CONTROL_LOG_H__ */
int len = 0;
int ret;
char *buf;
+ unsigned int bytes_read = 0;
- ret = read(fd, &len, sizeof(int));
- if (ret < sizeof(int)) {
+ ret = _read_socket(fd, (char *)&len, sizeof(int), &bytes_read);
+ if (ret != DATA_CONTROL_ERROR_NONE) {
_LOGE("read error :%d", ret);
return NULL;
}
_LOGE("calloc fail");
return NULL;
}
- ret = read(fd, buf, len);
- if (ret < len) {
+ ret = _read_socket(fd, buf, len, &bytes_read);
+ if (ret != DATA_CONTROL_ERROR_NONE) {
_LOGE("read error :%d", ret);
if (buf)
free(buf);
int ret;
int i;
bundle *data = NULL;
+ unsigned int bytes_read = 0;
data_control_bulk_data_create(&ret_bulk_data_h);
- ret = read(fd, &size, sizeof(int));
- if (ret < sizeof(int)) {
+
+ ret = _read_socket(fd, (char *)&size, sizeof(int), &bytes_read);
+ if (ret != DATA_CONTROL_ERROR_NONE) {
_LOGE("read error :%d", ret);
data_control_bulk_data_destroy(ret_bulk_data_h);
return NULL;