summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaya Sugiura <ssugiura@jp.adit-jv.com>2019-05-23 13:56:33 +0900
committerSaya Sugiura <ssugiura@jp.adit-jv.com>2019-06-18 17:22:09 +0900
commit3580c5640c5578f508e93a8a851231b389d327cd (patch)
treeefe0dd5b737e0192ea541861452c0f3f0edde099
parent341831da4da448392d62e48f1a4f419a18e3dca5 (diff)
downloadDLT-daemon-3580c5640c5578f508e93a8a851231b389d327cd.tar.gz
daemon: Remove bytes_sent
When it fails to send a log message to connected client, daemon tries to store the remaining partial message to internal ring buffer and send again later. When calculating the number of bytes which were sent to client, it had a bug which it keeps on incrementing instead of initializing the variable on every message, which never reached to the condition mentioned above and had a possibility to overflow and access invalid memory. On the other hand, daemon doesn't need to store the unsent partial message, as the socket to the client will be closed on failure and the sent partial message will be dropped anyways. This commit removes the lines where the daemon tries to store the partial message to ring buffer. With this, variable bytes_sent is now removed. Related commit: 2262f8b Made socket send reliable Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
-rw-r--r--include/dlt/dlt_common.h1
-rw-r--r--src/daemon/dlt_daemon_client.c28
-rw-r--r--src/daemon/dlt_daemon_connection.c5
-rw-r--r--src/daemon/dlt_daemon_socket.c12
-rw-r--r--src/daemon/dlt_daemon_socket.h2
-rw-r--r--src/shared/dlt_common.c1
6 files changed, 6 insertions, 43 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index fc02743..cab860d 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -769,7 +769,6 @@ typedef struct
char *buf; /**< pointer to position within receiver buffer */
char *backup_buf; /** pointer to the buffer with partial messages if any **/
int fd; /**< connection handle */
- int32_t bytes_sent; /**< total bytes sent in a single msg */
int32_t buffersize; /**< size of receiver buffer */
} DltReceiver;
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index 55afd7c..d8062d5 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -113,7 +113,6 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon,
DltConnection *temp = NULL;
int type_mask =
(DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL);
- uint8_t *tmp_buffer = NULL;
if ((daemon == NULL) || (daemon_local == NULL)) {
dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
@@ -142,33 +141,6 @@ static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon,
if ((ret != DLT_DAEMON_ERROR_OK) &&
(DLT_CONNECTION_CLIENT_MSG_TCP == temp->type)) {
- if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) {
- if (temp->receiver->bytes_sent < (size1 + size2)) {
- tmp_buffer = (uint8_t *)calloc(size1 + size2, sizeof(uint8_t));
-
- if (tmp_buffer == NULL) {
- dlt_vlog(LOG_ERR, "%s: Memory allocation failed.\n", __func__);
- return 0;
- }
-
- memcpy(tmp_buffer, data1, size1);
- memcpy(tmp_buffer + size1, data2, size2);
- DLT_DAEMON_SEM_LOCK();
-
- /* Store message in history buffer */
- if (dlt_buffer_push3(&(daemon->client_ringbuffer),
- tmp_buffer + temp->receiver->bytes_sent,
- (size1 + size2 - temp->receiver->bytes_sent),
- 0, 0, 0, 0) < DLT_RETURN_OK) {
- dlt_vlog(LOG_DEBUG, "%s: Buffer is full! Message discarded.\n", __func__);
- dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL);
- }
-
- free(tmp_buffer);
- DLT_DAEMON_SEM_FREE();
- }
- }
-
dlt_daemon_close_socket(temp->receiver->fd,
daemon,
daemon_local,
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 2fe17c1..456a075 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -71,7 +71,6 @@ DLT_STATIC int dlt_connection_send(DltConnection *conn,
size_t msg_size)
{
DltConnectionType type = DLT_CONNECTION_TYPE_MAX;
- int bytes_sent = 0;
int ret = 0;
if ((conn != NULL) && (conn->receiver != NULL))
@@ -88,9 +87,7 @@ DLT_STATIC int dlt_connection_send(DltConnection *conn,
case DLT_CONNECTION_CLIENT_MSG_TCP:
ret = dlt_daemon_socket_sendreliable(conn->receiver->fd,
msg,
- msg_size,
- &bytes_sent);
- conn->receiver->bytes_sent += bytes_sent;
+ msg_size);
return ret;
default:
return DLT_DAEMON_ERROR_UNKNOWN;
diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c
index f35346d..f9c4ab2 100644
--- a/src/daemon/dlt_daemon_socket.c
+++ b/src/daemon/dlt_daemon_socket.c
@@ -152,14 +152,12 @@ int dlt_daemon_socket_close(int sock)
int dlt_daemon_socket_send(int sock, void *data1, int size1, void *data2, int size2, char serialheader)
{
int ret = DLT_RETURN_OK;
- int bytes_sent = 0;
/* Optional: Send serial header, if requested */
if (serialheader) {
ret = dlt_daemon_socket_sendreliable(sock,
(void *)dltSerialHeader,
- sizeof(dltSerialHeader),
- &bytes_sent);
+ sizeof(dltSerialHeader));
if (ret != DLT_RETURN_OK)
return ret;
@@ -167,14 +165,14 @@ int dlt_daemon_socket_send(int sock, void *data1, int size1, void *data2, int si
/* Send data */
if ((data1 != NULL) && (size1 > 0)) {
- ret = dlt_daemon_socket_sendreliable(sock, data1, size1, &bytes_sent);
+ ret = dlt_daemon_socket_sendreliable(sock, data1, size1);
if (ret != DLT_RETURN_OK)
return ret;
}
if ((data2 != NULL) && (size2 > 0))
- ret = dlt_daemon_socket_sendreliable(sock, data2, size2, &bytes_sent);
+ ret = dlt_daemon_socket_sendreliable(sock, data2, size2);
return ret;
}
@@ -188,7 +186,7 @@ int dlt_daemon_socket_get_send_qeue_max_size(int sock)
return n;
}
-int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size, int *bytes_sent)
+int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size)
{
int data_sent = 0;
@@ -199,7 +197,6 @@ int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size
dlt_vlog(LOG_WARNING,
"dlt_daemon_socket_sendreliable: socket send failed [errno: %d]!\n",
errno);
- *bytes_sent = data_sent;
return DLT_DAEMON_ERROR_SEND_FAILED;
}
else {
@@ -207,7 +204,6 @@ int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size
}
}
- *bytes_sent = data_sent;
return DLT_DAEMON_ERROR_OK;
}
diff --git a/src/daemon/dlt_daemon_socket.h b/src/daemon/dlt_daemon_socket.h
index 7276b2d..a9ac008 100644
--- a/src/daemon/dlt_daemon_socket.h
+++ b/src/daemon/dlt_daemon_socket.h
@@ -76,6 +76,6 @@ int dlt_daemon_socket_send(int sock, void *data1, int size1, void *data2, int si
* @param message_size
* @return on sucess: DLT_DAEMON_ERROR_OK, on error: DLT_DAEMON_ERROR_SEND_FAILED
*/
-int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size, int *bytes_sent);
+int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size);
#endif /* DLT_DAEMON_SOCKET_H */
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index bbbd682..0e8ebd2 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -1896,7 +1896,6 @@ DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
receiver->lastBytesRcvd = 0;
receiver->bytesRcvd = 0;
receiver->totalBytesRcvd = 0;
- receiver->bytes_sent = 0;
receiver->buffersize = buffersize;
receiver->fd = fd;
receiver->buffer = (char *)malloc(receiver->buffersize);