Problem when getting data from syslog-ng into a socket program
Hi, I have a little problem which I need to solve. I wrote a small program, which listens to the syslog-ng. I think I have encountered a problem with the timing I'm connecting and disconnecting to the syslog-ng. I almost always get the following msg with other msgs, <43>Aug 11 19:39:03 diluka-laptop syslog-ng[5084]: Connection broken; time_reopen='10' <43>Aug 11 19:39:13 diluka-laptop syslog-ng[5084]: EOF occurred while idle; fd='20' Please let me know whether following code snippet has anything irrelevent or unsuitable. while(1) { int len, read = 0; new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size); while((len = recv (new_fd, buffer, BUFF_SIZE - 1, MSG_PEEK)) > 0) { read = recv(sockfd, buffer, BUFF_SIZE - 1, 0); buffer[read] = '\0'; printf(buffer); memset(buffer, '\0', BUFF_SIZE * sizeof(char)); break; } close(new_fd); new_fd = 0; } I highly appreciate if you can give some help for me to get the problem solved. Thanks, Diluka.
Hi, Can anybody pls help me to figure out the problem ?? I only need to know what does these two lines means <43>Aug 11 19:39:03 diluka-laptop syslog-ng[5084]: Connection broken; time_reopen='10' <43>Aug 11 19:39:13 diluka-laptop syslog-ng[5084]: EOF occurred while idle; fd='20' I highly appreciate if you could provide some help. Thanks, Diluka. Diluka Moratuwage wrote:
Hi, I have a little problem which I need to solve. I wrote a small program, which listens to the syslog-ng. I think I have encountered a problem with the timing I'm connecting and disconnecting to the syslog-ng.
I almost always get the following msg with other msgs,
<43>Aug 11 19:39:03 diluka-laptop syslog-ng[5084]: Connection broken; time_reopen='10' <43>Aug 11 19:39:13 diluka-laptop syslog-ng[5084]: EOF occurred while idle; fd='20'
Please let me know whether following code snippet has anything irrelevent or unsuitable.
while(1) { int len, read = 0; new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
while((len = recv (new_fd, buffer, BUFF_SIZE - 1, MSG_PEEK)) > 0) { read = recv(sockfd, buffer, BUFF_SIZE - 1, 0); buffer[read] = '\0'; printf(buffer); memset(buffer, '\0', BUFF_SIZE * sizeof(char)); break; } close(new_fd); new_fd = 0; }
I highly appreciate if you can give some help for me to get the problem solved.
Thanks, Diluka. _______________________________________________ syslog-ng maillist - syslog-ng@lists.balabit.hu https://lists.balabit.hu/mailman/listinfo/syslog-ng Frequently asked questions at http://www.campin.net/syslog-ng/faq.html
On Sat, 2007-08-11 at 23:10 +0530, Diluka Moratuwage wrote:
Hi,
Can anybody pls help me to figure out the problem ?? I only need to know what does these two lines means
<43>Aug 11 19:39:03 diluka-laptop syslog-ng[5084]: Connection broken; time_reopen='10' <43>Aug 11 19:39:13 diluka-laptop syslog-ng[5084]: EOF occurred while idle; fd='20'
I highly appreciate if you could provide some help.
syslog-ng does not expect the log channel to be closed, that's what those messages mean: the log channel was unexpectedly closed. -- Bazsi
Hi, Thanks for your reply. Yea I just understood it. Now I'm not going to forceably close the connection. And I don't use the recv() function anymore. When I'm using the read() funtion it worked. Thanks, Diluka. Balazs Scheidler wrote:
syslog-ng does not expect the log channel to be closed, that's what those messages mean: the log channel was unexpectedly closed.
On Mon, 2007-08-13 at 15:18 +0530, Diluka Moratuwage wrote:
Hi, Thanks for your reply. Yea I just understood it. Now I'm not going to forceably close the connection. And I don't use the recv() function anymore. When I'm using the read() funtion it worked.
it should not matter whether you use recv() or read(). read() is equivalent to calling recv() with 0 as flags. -- Bazsi
participants (2)
-
Balazs Scheidler
-
Diluka Moratuwage