Hi, I'm trying to adapt the example server to get messages on a loop,
with a timeout.
I set the timeout with ioctl_rt to 500ms (0,5s), and then call
rt_dev_recv from inside the loop. Unfurtunately, no matter what value i
set the timeout, it always times out imeediately (half a second should
be noticeable by me). If i set it to 0, it blocks OK.
If i send something to it, it does get received, because i loop around
the recv. But that is not the desired behaviour.
Sorry if this question seems stupid, but does anyone know where the
problem might be, or where i could get some information?
Thanks in advance,
Paulo Schreiner
/* simpleserver.c
*
* simpleserver - a simple server for demonstration of rtnet's lxrt
interface
* 06/2003 by Hans-Peter Bock <[EMAIL PROTECTED]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sched.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <signal.h>
#include <rtai_lxrt.h>
#include <rtnet.h>
static struct sockaddr_in local_addr;
volatile static int end = 0;
void endme(int sig) {
printf("Signal\n");
end = 1; }
int main(int argc, char *argv[]) {
int sockfd = 0;
int ret = 0;
char msg[4000];
int64_t TimeOut;
RT_TASK *lxrtnettsk;
/* register signals */
signal(SIGHUP, endme);
signal(SIGKILL, endme);
signal(SIGTERM, endme);
signal(SIGALRM, endme);
/* Set variables to zero. */
memset(msg, 0, sizeof(msg));
memset(&local_addr, 0, sizeof (struct sockaddr_in));
printf("RTnet, simpleserver for LXRT\n");
/* Check arguments and set addresses. */
if (argc == 2) {
local_addr.sin_family = AF_INET;
local_addr.sin_addr.s_addr = INADDR_ANY;
local_addr.sin_port = htons(atoi(argv[1]));
} else {
fprintf(stderr,
"Usage: "
"%s <local-port>\n",
argv[0]);
exit(1);
}
/* Lock allocated memory into RAM. */
mlockall(MCL_CURRENT|MCL_FUTURE);
/* Create new socket. */
sockfd = rt_dev_socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
printf("Error opening socket: %d\n", sockfd);
exit(1);
}
/* set timeout */
TimeOut = 500000000;
printf("Timeout = %i\n", TimeOut);
ioctl_rt(sockfd, RTNET_RTIOC_TIMEOUT, &TimeOut);
/* Initialize a real time buddy. */
lxrtnettsk = rt_task_init(4900, 1, 0, 0);
if (NULL == lxrtnettsk) {
rt_dev_close(sockfd);
printf("CANNOT INIT MASTER TASK\n");
exit(1);
}
/* Switch over to hard realtime mode. */
rt_make_hard_real_time();
/* Bind socket to local address specified as parameter. */
ret = rt_dev_bind(sockfd, (struct sockaddr *) &local_addr,
sizeof(struct sockaddr_in));
int i = 0;
while(i++ < 10) {
/* Block until packet is received. */
ret = rt_dev_recv(sockfd, msg, sizeof(msg), 0);
if(ret < 0) {
printf("Error %i\n", ret);
//break;
}
//else {
/* this breaks real time, but is useful for testing. Should be
changed
to some kind
* of RTAI message (Paulo) */
printf("(%i) Received message: \"%s\"\n", i, msg);
//}
}
/* Switch over to soft realtime mode. */
rt_make_soft_real_time();
/* Close socket.
* Note: call must be in soft-mode because socket was created as
non-rt! */
rt_dev_close(sockfd);
/* Stop the timer. */
stop_rt_timer();
/* Delete realtime buddy. */
rt_task_delete(lxrtnettsk);
//printf("Received message: \"%s\"\n", msg);
printf("ended\n");
return 0;
}
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
RTnet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rtnet-users