summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-12-19 10:18:03 +0100
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2014-01-10 07:16:14 +0100
commit9b74a8457aaa9b282cf79427a713b907635d82a2 (patch)
treee09145e56abd101db80657f52ef79918ce0aa86d
parent8029c1387c240fcd085be13f38d9adadc97c03bf (diff)
downloadDLT-daemon-9b74a8457aaa9b282cf79427a713b907635d82a2.tar.gz
Cleanup of send return values. Further cleanup of send restructure.
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r--src/daemon/dlt-daemon.c107
-rwxr-xr-xsrc/daemon/dlt-daemon.h6
-rw-r--r--src/daemon/dlt_daemon_client.c99
-rw-r--r--src/daemon/dlt_daemon_client.h2
-rw-r--r--src/daemon/dlt_daemon_common.c7
-rw-r--r--src/daemon/dlt_daemon_common.h7
-rw-r--r--src/daemon/dlt_daemon_serial.c10
-rw-r--r--src/daemon/dlt_daemon_socket.c24
-rw-r--r--src/daemon/dlt_daemon_socket.h2
-rw-r--r--src/shared/dlt_offline_trace.c2
10 files changed, 164 insertions, 102 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 9ace6f0..b10237c 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -489,7 +489,7 @@ int main(int argc, char* argv[])
}
if(daemon_local.flags.yvalue[0])
- dlt_daemon_change_state(&daemon,DLT_DAEMON_STATE_SEND_DIRECT);
+ dlt_daemon_change_state(&daemon,DLT_DAEMON_STATE_SEND_DIRECT);
else
dlt_daemon_change_state(&daemon,DLT_DAEMON_STATE_BUFFER);
@@ -566,7 +566,14 @@ int main(int argc, char* argv[])
// Activity received on timer_wd, but unable to read the fd:
// let's go on sending notification
}
- if (daemon.timingpackets)
+ if(daemon.state == DLT_DAEMON_STATE_SEND_BUFFER || daemon.state == DLT_DAEMON_STATE_BUFFER_FULL)
+ {
+ if (dlt_daemon_send_ringbuffer_to_client(&daemon, &daemon_local, daemon_local.flags.vflag))
+ {
+ dlt_log(LOG_DEBUG,"Can't send contents of ringbuffer to clients\n");
+ }
+ }
+ if (daemon.timingpackets && daemon.state == DLT_DAEMON_STATE_SEND_DIRECT)
{
dlt_daemon_control_message_time(DLT_DAEMON_SEND_TO_ALL, &daemon, &daemon_local, daemon_local.flags.vflag);
}
@@ -1159,6 +1166,10 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_
if (setsockopt (in_sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout_send, sizeof(timeout_send)) < 0)
dlt_log(LOG_ERR, "setsockopt failed\n");
+ /* Set to non blocking mode */
+ //flags = fcntl(in_sock, F_GETFL, 0);
+ //fcntl(in_sock, F_SETFL, flags | O_NONBLOCK);
+
//sprintf("str,"Client Connection from %s\n", inet_ntoa(cli.sin_addr));
//dlt_log(str);
FD_SET(in_sock, &(daemon_local->master)); /* add to master set */
@@ -1192,12 +1203,11 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_
if (daemon_local->client_connections==1)
{
- dlt_daemon_change_state(daemon,DLT_DAEMON_STATE_SEND_BUFFER);
-
if (daemon_local->flags.vflag)
{
dlt_log(LOG_INFO, "Send ring-buffer to client\n");
}
+ dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_SEND_BUFFER);
if (dlt_daemon_send_ringbuffer_to_client(daemon, daemon_local, verbose)==-1)
{
dlt_log(LOG_ERR,"Can't send contents of ringbuffer to clients\n");
@@ -1495,7 +1505,8 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l
int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
- DltUserControlMsgBufferOverflow *userpayload;
+ int ret;
+ DltUserControlMsgBufferOverflow *userpayload;
PRINT_FUNCTION_VERBOSE(verbose);
@@ -1515,20 +1526,13 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *
userpayload = (DltUserControlMsgBufferOverflow*) (daemon_local->receiver.buf+sizeof(DltUserHeader));
/* Store in daemon, that a message buffer overflow has occured */
- daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
-
- /* look if TCP connection to client is available */
- dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, userpayload->overflow_counter,userpayload->apid,verbose);
-
- /* Reset overflow state */
- daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
-
- if(0)
+ /* look if TCP connection to client is available or it least message can be put into buffer */
+ if((ret=dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, userpayload->overflow_counter,userpayload->apid,verbose)))
{
- /* there was an error when storing message */
- /* add the counter of lost messages to the daemon counter */
- daemon->overflow_counter+=userpayload->overflow_counter;
- }
+ /* there was an error when storing message */
+ /* add the counter of lost messages to the daemon counter */
+ daemon->overflow_counter+=userpayload->overflow_counter;
+ }
/* keep not read data in buffer */
if (dlt_receiver_remove(&(daemon_local->receiver),sizeof(DltUserHeader)+sizeof(DltUserControlMsgBufferOverflow))==-1)
@@ -1542,29 +1546,22 @@ int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *
int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
+ int ret;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon==0) || (daemon_local==0))
{
dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_message_overflow()\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
/* Store in daemon, that a message buffer overflow has occured */
- daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
-
- dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local,daemon->overflow_counter,"", verbose);
-
- /* Reset overflow state */
- daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
-
- /* message was not sent, so report to caller that sending failed */
- if (0)
- {
- return -1;
- }
+ if((ret=dlt_daemon_control_message_buffer_overflow(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local,daemon->overflow_counter,"", verbose)))
+ {
+ return ret;
+ }
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
@@ -1900,6 +1897,7 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, DltDae
int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
+ int ret;
int bytes_to_be_removed;
static char text[DLT_DAEMON_TEXTSIZE];
@@ -1909,7 +1907,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if ((daemon==0) || (daemon_local==0))
{
dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_message_log()\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
if (dlt_message_read(&(daemon_local->msg),(unsigned char*)daemon_local->receiver.buf+sizeof(DltUserHeader),daemon_local->receiver.bytesRcvd-sizeof(DltUserHeader),0,verbose)==0)
@@ -1923,7 +1921,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if (dlt_message_set_extraparameters(&(daemon_local->msg),0)==-1)
{
dlt_log(LOG_ERR,"Can't set message extra parameters in process user message log\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
/* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */
@@ -1936,7 +1934,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon_local->msg.headerextra.ecu)==-1)
{
dlt_log(LOG_ERR,"Can't set storage header in process user message log\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
}
else
@@ -1944,7 +1942,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon->ecuid)==-1)
{
dlt_log(LOG_ERR,"Can't set storage header in process user message log\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
}
@@ -1989,9 +1987,14 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH))
{
- dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),
- daemon_local->msg.databuffer,daemon_local->msg.datasize,
- 0/* no ringbuffer operation */,verbose);
+ if((ret = dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),
+ daemon_local->msg.databuffer,daemon_local->msg.datasize,verbose)))
+ {
+ if(ret == DLT_DAEMON_ERROR_BUFFER_FULL)
+ {
+ daemon->overflow_counter++;
+ }
+ }
}
}
@@ -2005,16 +2008,16 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo
if (dlt_receiver_remove(&(daemon_local->receiver),bytes_to_be_removed)==-1)
{
dlt_log(LOG_ERR,"Can't remove bytes from receiver\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
}
else
{
dlt_log(LOG_ERR,"Can't read messages from receiver\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
#ifdef DLT_SHM_ENABLE
@@ -2312,6 +2315,7 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *
int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
+ int ret;
static uint8_t data[DLT_DAEMON_RCVBUFSIZE];
int length;
@@ -2320,28 +2324,33 @@ int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daem
if ((daemon==0) || (daemon_local==0))
{
dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_send_ringbuffer_to_client()\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
if(dlt_buffer_get_message_count(&(daemon->client_ringbuffer)) <= 0)
{
dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_SEND_DIRECT);
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
- /* Attention: If the message can't be send at this time, it will be silently discarded. */
- while ( (length = dlt_buffer_pull(&(daemon->client_ringbuffer), data, sizeof(data)) ) > 0)
+ while ( (length = dlt_buffer_copy(&(daemon->client_ringbuffer), data, sizeof(data)) ) > 0)
{
- dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,data,length,0,0,1/* ringbuffer operation */,verbose);
+ if((ret = dlt_daemon_client_send(DLT_DAEMON_SEND_FORCE,daemon,daemon_local,data,length,0,0,verbose)))
+ {
+ return ret;
+ }
+ dlt_buffer_remove(&(daemon->client_ringbuffer));
+ if(daemon->state != DLT_DAEMON_STATE_SEND_BUFFER)
+ dlt_daemon_change_state(daemon,DLT_DAEMON_STATE_SEND_BUFFER);
if(dlt_buffer_get_message_count(&(daemon->client_ringbuffer)) <= 0)
{
dlt_daemon_change_state(daemon,DLT_DAEMON_STATE_SEND_DIRECT);
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, int* fd, const char* timer_name)
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 04def07..69c679e 100755
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -154,6 +154,12 @@ typedef struct
typedef DltDaemonTimingPacketThreadData DltDaemonECUVersionThreadData;
+#define DLT_DAEMON_ERROR_OK 0
+#define DLT_DAEMON_ERROR_UNKNOWN -1
+#define DLT_DAEMON_ERROR_BUFFER_FULL -2
+#define DLT_DAEMON_ERROR_SEND_FAILED -3
+#define DLT_DAEMON_ERROR_WRITE_FAILED -4
+
/* Function prototypes */
void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index 352c912..0dcfbe9 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -81,22 +81,23 @@
/** Global text output buffer, mainly used for creation of error/warning strings */
static char str[DLT_DAEMON_TEXTBUFSIZE];
-int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_local,void* data1,int size1,void* data2,int size2,char ringbuffer,int verbose)
+int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_local,void* data1,int size1,void* data2,int size2,int verbose)
{
+ int ret;
int j,third_value;
- if (sock!=DLT_DAEMON_SEND_TO_ALL)
+ if (sock!=DLT_DAEMON_SEND_TO_ALL && sock!=DLT_DAEMON_SEND_FORCE)
{
/* Send message to specific socket */
if (isatty(sock))
{
DLT_DAEMON_SEM_LOCK();
- if(dlt_daemon_serial_send(sock,data1,size1,data2,size2,daemon->sendserialheader))
+ if((ret=dlt_daemon_serial_send(sock,data1,size1,data2,size2,daemon->sendserialheader)))
{
- dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: serial send dlt message failed\n");
DLT_DAEMON_SEM_FREE();
- return -1;
+ dlt_log(LOG_WARNING,"dlt_daemon_client_send: serial send dlt message failed\n");
+ return ret;
}
DLT_DAEMON_SEM_FREE();
@@ -105,32 +106,36 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc
{
DLT_DAEMON_SEM_LOCK();
- if(dlt_daemon_socket_send(sock,data1,size1,data2,size2,daemon->sendserialheader))
+ if((ret=dlt_daemon_socket_send(sock,data1,size1,data2,size2,daemon->sendserialheader)))
{
- dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: socket send dlt message failed\n");
DLT_DAEMON_SEM_FREE();
- return -1;
+ dlt_log(LOG_WARNING,"dlt_daemon_client_send: socket send dlt message failed\n");
+ return ret;
}
DLT_DAEMON_SEM_FREE();
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
/* write message to offline trace */
- if (!ringbuffer && (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT))
+ if ((sock!=DLT_DAEMON_SEND_FORCE) && (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT))
{
if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH))
&& daemon_local->flags.offlineTraceDirectory[0])
{
- dlt_offline_trace_write(&(daemon_local->offlineTrace),daemon_local->msg.headerbuffer,daemon_local->msg.headersize,
- daemon_local->msg.databuffer,daemon_local->msg.datasize,0,0);
+ if(dlt_offline_trace_write(&(daemon_local->offlineTrace),daemon_local->msg.headerbuffer,daemon_local->msg.headersize,
+ daemon_local->msg.databuffer,daemon_local->msg.datasize,0,0))
+ {
+ return DLT_DAEMON_ERROR_WRITE_FAILED;
+ }
}
}
/* send messages to daemon socket */
- if (ringbuffer || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT))
+ if ((sock==DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT))
{
+ int sent = 0;
/* look if TCP connection to client is available */
for (j = 0; j <= daemon_local->fdmax; j++)
{
@@ -157,9 +162,11 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc
{
DLT_DAEMON_SEM_LOCK();
- if(dlt_daemon_serial_send(j,data1,size1,data2,size2,daemon->sendserialheader))
+ if((ret=dlt_daemon_serial_send(j,data1,size1,data2,size2,daemon->sendserialheader)))
{
- dlt_log(LOG_WARNING,"dlt_daemon_send_all: serial send dlt message failed\n");
+ DLT_DAEMON_SEM_FREE();
+ dlt_log(LOG_WARNING,"dlt_daemon_client_send: serial send dlt message failed\n");
+ return ret;
}
DLT_DAEMON_SEM_FREE();
@@ -168,46 +175,59 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc
{
DLT_DAEMON_SEM_LOCK();
- if(dlt_daemon_socket_send(j,data1,size1,data2,size2,daemon->sendserialheader))
+ if((ret=dlt_daemon_socket_send(j,data1,size1,data2,size2,daemon->sendserialheader)))
{
- dlt_log(LOG_WARNING,"dlt_daemon_send_all: socket send dlt message failed\n");
+ DLT_DAEMON_SEM_FREE();
+ dlt_log(LOG_WARNING,"dlt_daemon_client_send: socket send dlt message failed\n");
dlt_daemon_close_socket(j, daemon, daemon_local, verbose);
+ return ret;
}
DLT_DAEMON_SEM_FREE();
}
+ sent=1;
}
}
}
+ if((sock==DLT_DAEMON_SEND_FORCE) && !sent)
+ {
+ return DLT_DAEMON_ERROR_SEND_FAILED;
+ }
}
/* Message was not sent to client, so store it in client ringbuffer */
- if (!ringbuffer && (daemon->state == DLT_DAEMON_STATE_BUFFER || daemon->state == DLT_DAEMON_STATE_SEND_BUFFER))
+ if ((sock!=DLT_DAEMON_SEND_FORCE) && (daemon->state == DLT_DAEMON_STATE_BUFFER || daemon->state == DLT_DAEMON_STATE_SEND_BUFFER || daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))
{
+ if(daemon->state == DLT_DAEMON_STATE_BUFFER_FULL)
+ return DLT_DAEMON_ERROR_BUFFER_FULL;
+
DLT_DAEMON_SEM_LOCK();
/* Store message in history buffer */
if (dlt_buffer_push3(&(daemon->client_ringbuffer),data1,size1,data2,size2,0, 0)<0)
{
DLT_DAEMON_SEM_FREE();
- dlt_log(LOG_ERR,"dlt_daemon_send_all: Buffer is full! Message discarded.\n");
+ dlt_log(LOG_DEBUG,"dlt_daemon_client_send: Buffer is full! Message discarded.\n");
+ dlt_daemon_change_state(daemon,DLT_DAEMON_STATE_BUFFER_FULL);
+ return DLT_DAEMON_ERROR_BUFFER_FULL;
}
DLT_DAEMON_SEM_FREE();
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
int dlt_daemon_client_send_control_message( int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, char* appid, char* ctid, int verbose)
{
+ int ret;
int32_t len;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon==0) || (msg==0) || (appid==0) || (ctid==0))
{
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
/* prepare storage header */
@@ -215,7 +235,7 @@ int dlt_daemon_client_send_control_message( int sock, DltDaemon *daemon, DltDaem
if (dlt_set_storageheader(msg->storageheader,daemon->ecuid)==-1)
{
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
/* prepare standard header */
@@ -266,20 +286,20 @@ int dlt_daemon_client_send_control_message( int sock, DltDaemon *daemon, DltDaem
if (len>UINT16_MAX)
{
dlt_log(LOG_CRIT,"Huge control message discarded!\n");
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len));
- if(dlt_daemon_client_send(sock,daemon,daemon_local,msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),
- msg->databuffer,msg->datasize,0/* no ringbuffer operation */,verbose))
+ if((ret=dlt_daemon_client_send(sock,daemon,daemon_local,msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),
+ msg->databuffer,msg->datasize,verbose)))
{
DLT_DAEMON_SEM_FREE();
- dlt_log(LOG_ERR,"dlt_daemon_control_send_control_message: DLT message send to all failed!.\n");
- return -1;
+ dlt_log(LOG_DEBUG,"dlt_daemon_control_send_control_message: DLT message send to all failed!.\n");
+ return ret;
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
@@ -923,6 +943,7 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal
int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, unsigned int overflow_counter,char* apid, int verbose)
{
+ int ret;
DltMessage msg;
DltServiceMessageBufferOverflowResponse *resp;
@@ -930,14 +951,14 @@ int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, DltD
if (daemon==0)
{
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
/* initialise new message */
if (dlt_message_init(&msg,0)==-1)
{
dlt_daemon_control_service_response(sock, daemon,daemon_local, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
/* prepare payload of data */
@@ -953,26 +974,26 @@ int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, DltD
}
if (msg.databuffer==0)
{
- return -1;
+ return DLT_DAEMON_ERROR_UNKNOWN;
}
resp = (DltServiceMessageBufferOverflowResponse*) msg.databuffer;
resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW;
resp->status = DLT_SERVICE_RESPONSE_OK;
- resp->overflow = daemon->message_buffer_overflow;
+ resp->overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
resp->overflow_counter = overflow_counter;
/* send message */
- if(dlt_daemon_client_send_control_message(sock,daemon,daemon_local,&msg,apid,"", verbose))
+ if((ret=dlt_daemon_client_send_control_message(sock,daemon,daemon_local,&msg,apid,"", verbose)))
{
dlt_message_free(&msg,0);
- return -1;
+ return ret;
}
/* free message */
dlt_message_free(&msg,0);
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, uint32_t service_id, int8_t status , int verbose)
@@ -1499,6 +1520,7 @@ void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltDaemo
void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
+ int ret;
DltMessage msg;
int32_t len;
@@ -1562,8 +1584,11 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal
msg.standardheader->len = DLT_HTOBE_16(((uint16_t)len));
/* Send message */
- dlt_daemon_client_send(sock,daemon,daemon_local,msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),
- msg.databuffer,msg.datasize,0 /* no ringbuffer only */,verbose);
+ if((ret = dlt_daemon_client_send(sock,daemon,daemon_local,msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),
+ msg.databuffer,msg.datasize,verbose)))
+ {
+
+ }
/* free message */
dlt_message_free(&msg,0);
diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h
index 6d0100f..b46d8c7 100644
--- a/src/daemon/dlt_daemon_client.h
+++ b/src/daemon/dlt_daemon_client.h
@@ -62,7 +62,7 @@
#include <dlt_offline_trace.h>
#include <sys/time.h>
-int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_local,void* data1,int size1,void* data2,int size2,char ringbuffer,int verbose);
+int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_local,void* data1,int size1,void* data2,int size2,int verbose);
/**
* Send out response message to dlt client
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index fa6959c..be6fa26 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -139,7 +139,6 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose
daemon->default_log_level = DLT_DAEMON_INITIAL_LOG_LEVEL ;
daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
- daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
daemon->overflow_counter = 0;
daemon->runtime_context_cfg_loaded = 0;
@@ -1197,8 +1196,6 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *f
daemon->default_log_level = DLT_DAEMON_INITIAL_LOG_LEVEL ;
daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
- daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
-
/* Reset all other things (log level, trace status, etc.
to default values */
@@ -1280,6 +1277,10 @@ void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState)
dlt_log(LOG_INFO,"Switched to buffer state.\n");
daemon->state = DLT_DAEMON_STATE_BUFFER;
break;
+ case DLT_DAEMON_STATE_BUFFER_FULL:
+ dlt_log(LOG_INFO,"Switched to buffer full state.\n");
+ daemon->state = DLT_DAEMON_STATE_BUFFER_FULL;
+ break;
case DLT_DAEMON_STATE_SEND_BUFFER:
dlt_log(LOG_INFO,"Switched to send buffer state.\n");
daemon->state = DLT_DAEMON_STATE_SEND_BUFFER;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 41d741b..4c92c43 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -87,6 +87,7 @@ extern "C" {
#define DLT_DAEMON_RINGBUFFER_STEP_SIZE 500000 /**< Ring buffer size for storing log messages while no client is connected */
#define DLT_DAEMON_SEND_TO_ALL -3 /**< Constant value to identify the command "send to all" */
+#define DLT_DAEMON_SEND_FORCE -4 /**< Constant value to identify the command "send force to all" */
/* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */
@@ -101,8 +102,9 @@ typedef enum
{
DLT_DAEMON_STATE_INIT = 0, /**< Initial state */
DLT_DAEMON_STATE_BUFFER = 1, /**< logging is buffered until external logger is connected or internal logging is activated */
- DLT_DAEMON_STATE_SEND_BUFFER = 2, /**< external logger is connected, but buffer is still not empty or external logger queue is full */
- DLT_DAEMON_STATE_SEND_DIRECT = 3 /**< External logger is connected or internal logging is active, and buffer is empty */
+ DLT_DAEMON_STATE_BUFFER_FULL = 2, /**< then internal buffer is full, wait for connect from client */
+ DLT_DAEMON_STATE_SEND_BUFFER = 3, /**< external logger is connected, but buffer is still not empty or external logger queue is full */
+ DLT_DAEMON_STATE_SEND_DIRECT = 4 /**< External logger is connected or internal logging is active, and buffer is empty */
} DltDaemonState;
/**
@@ -142,7 +144,6 @@ typedef struct
DltDaemonApplication *applications; /**< Pointer to applications */
int8_t default_log_level; /**< Default log level (of daemon) */
int8_t default_trace_status; /**< Default trace status (of daemon) */
- int message_buffer_overflow; /**< Set to one, if buffer overflow has occured, zero otherwise */
unsigned int overflow_counter; /**< counts the number of lost messages. */
int runtime_context_cfg_loaded; /**< Set to one, if runtime context configuration has been loaded, zero otherwise */
char ecuid[DLT_ID_SIZE]; /**< ECU ID of daemon */
diff --git a/src/daemon/dlt_daemon_serial.c b/src/daemon/dlt_daemon_serial.c
index 2dce5a8..36bf049 100644
--- a/src/daemon/dlt_daemon_serial.c
+++ b/src/daemon/dlt_daemon_serial.c
@@ -59,6 +59,8 @@
#include <sys/types.h> /* send() */
#include <sys/socket.h> /* send() */
+#include "dlt-daemon.h"
+
#include "dlt_types.h"
#include "dlt_daemon_serial.h"
@@ -69,7 +71,7 @@ int dlt_daemon_serial_send(int sock,void* data1,int size1,void* data2,int size2,
if (serialheader)
{
if ( 0 > write(sock, dltSerialHeader,sizeof(dltSerialHeader)) )
- return -1;
+ return DLT_DAEMON_ERROR_SEND_FAILED;
}
@@ -77,14 +79,14 @@ int dlt_daemon_serial_send(int sock,void* data1,int size1,void* data2,int size2,
if(data1 && size1>0)
{
if (0 > write(sock, data1,size1))
- return -1;
+ return DLT_DAEMON_ERROR_SEND_FAILED;
}
if(data2 && size2>0)
{
if (0 > write(sock, data2,size2))
- return -1;
+ return DLT_DAEMON_ERROR_SEND_FAILED;
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c
index 033ea15..1492831 100644
--- a/src/daemon/dlt_daemon_socket.c
+++ b/src/daemon/dlt_daemon_socket.c
@@ -61,6 +61,8 @@
#include <syslog.h>
#include <errno.h>
#include <pthread.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
#include <sys/timerfd.h>
#include <sys/stat.h>
@@ -113,6 +115,10 @@ int dlt_daemon_socket_open(int *sock)
return -1;
} /* if */
+ /* get socket buffer size */
+ sprintf(str,"dlt_daemon_socket_open: Socket send queue size: %d\n",dlt_daemon_socket_get_send_qeue_max_size(*sock));
+ dlt_log(LOG_INFO, str);
+
return 0; /* OK */
}
@@ -129,7 +135,7 @@ int dlt_daemon_socket_send(int sock,void* data1,int size1,void* data2,int size2,
if (serialheader)
{
if ( 0 > send(sock, dltSerialHeader,sizeof(dltSerialHeader),0) )
- return -1;
+ return DLT_DAEMON_ERROR_SEND_FAILED;
}
@@ -137,14 +143,24 @@ int dlt_daemon_socket_send(int sock,void* data1,int size1,void* data2,int size2,
if(data1 && size1>0)
{
if (0 > send(sock, data1,size1,0))
- return -1;
+ return DLT_DAEMON_ERROR_SEND_FAILED;
}
if(data2 && size2>0)
{
if (0 > send(sock, data2,size2,0))
- return -1;
+ return DLT_DAEMON_ERROR_SEND_FAILED;
}
- return 0;
+ return DLT_DAEMON_ERROR_OK;
}
+
+int dlt_daemon_socket_get_send_qeue_max_size(int sock)
+{
+ int n = 0;
+ unsigned int m = sizeof(n);
+ getsockopt(sock,SOL_SOCKET,SO_SNDBUF,(void *)&n, &m);
+
+ return n;
+}
+
diff --git a/src/daemon/dlt_daemon_socket.h b/src/daemon/dlt_daemon_socket.h
index 6e2f90f..1ab7346 100644
--- a/src/daemon/dlt_daemon_socket.h
+++ b/src/daemon/dlt_daemon_socket.h
@@ -61,6 +61,8 @@
int dlt_daemon_socket_open(int *sock);
int dlt_daemon_socket_close(int sock);
+int dlt_daemon_socket_get_send_qeue_max_size(int sock);
+
int dlt_daemon_socket_send(int sock,void* data1,int size1,void* data2,int size2,char serialheader);
#endif /* DLT_DAEMON_SOCKET_H */
diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c
index 197d796..be29831 100644
--- a/src/shared/dlt_offline_trace.c
+++ b/src/shared/dlt_offline_trace.c
@@ -216,7 +216,7 @@ int dlt_offline_trace_write(DltOfflineTrace *trace,unsigned char *data1,int size
{
/* close old file */
close(trace->ohandle);
- trace->ohandle = -1;
+ trace->ohandle = -1;
/* check complete offline trace size, remove old logs if needed */
dlt_offline_trace_check_size(trace);