On Mon, Oct 11, 2010 at 2:42 PM, Gilles Chanteperdrix <
gilles.chanteperd...@xenomai.org> wrote:

> Johan Cockx wrote:
> >
> >
> > On Fri, Oct 8, 2010 at 11:16 AM, Gilles Chanteperdrix
> > <gilles.chanteperd...@xenomai.org
> > <mailto:gilles.chanteperd...@xenomai.org>> wrote:
> >
> >     Johan Cockx wrote:
> >     > Yes XENO_OPT_POSIX_SELECT is enabled and the xeno_posix module is
> >     loaded.
> >
> >     Ok. So, next question, are you sure you use the Xenomai posix skin
> >     wrapped select? You can try and put a printk in Xenomai's select
> syscall
> >     implementation to be sure that you go there.
> >
> >
> > Ok; it seems that I am not using the posix skin wrapped select: I added
> > a printk in the select syscall and it doesn't appear in the output of
> dmesg.
> >
> >  I am using `xeno-config --posix-cflags` for compilation and
> > `xeno-config --posix-ldflags` for linking. What else could be wrong?
>
> If you have a self-contained test case which allow to reproduce reliably
> this issue, and you are 100% sure that the kernel you are running has
> XENO_OPT_POSIX_SELECT. Please send it to the xenomai-help mailing list.
>

A printf in src/skins/posix/select.c confirms that __wrap_select is called.

In ksrc/skins/posix/syscall.c,  I added the following lines:
#ifndef CONFIG_XENO_OPT_POSIX_SELECT
#error XENO_OPT_POSIX_SELECT not enabled
#endif
It still compiles,  so I am quite sure that XENO_OPT_POSIX_SELECT is
enabled.

Attached is a small stand-alone test case.  It consists of two programs:
recv.c will wait for a udp message with a timeout of 10 sec (using select),
and send.c will send a udp message. If recv is started and then send (in
another terminal),  recv should return immediatly without timeout;
however,  it continues to wait until a timeout occurs.

gcc -Wall `xeno-config --posix-cflags` `xeno-config --posix-ldflags` send.c
-o send
gcc -Wall `xeno-config --posix-cflags` `xeno-config --posix-ldflags` recv.c
-o recv
./recv                                          # In one terminal
./send hello <ip-address>             # In another terminal, within 10 sec

I am currently running kernel version 2.6.26.8-ipipe-2.0-18, Xenomai 2.4 and
gcc 4.3.2.

Johan


> --
>                                             Gilles.
>
#include <err.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv) {
  if (argc > 2) {
    errx(1,"Usage: %s [<port>]",argv[0]);
  }
  int port = argc > 1 ? atoi(argv[1]): 32641;
  
  // Create socket
  int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (sock < 0) err(1,"cannot create socket");

  // Bind socket to port number
  struct sockaddr_in address;
  memset(&address, 0, sizeof(address));
  address.sin_family = PF_INET;
  address.sin_addr.s_addr = htonl(INADDR_ANY); 
  address.sin_port = htons(port);
  if (bind(sock,(struct sockaddr *)&address,sizeof(address)) < 0) {
    close(sock);
    err(1,"cannot bind to port %d",port);
  }

  fd_set rfds;
  FD_ZERO(&rfds);
  FD_SET(sock,&rfds);

  struct timeval tv;
  tv.tv_sec = 10;
  tv.tv_usec = 0;

#if 1
    int rv = select(sock+1,&rfds,NULL,NULL,&tv);
    if (rv < 0) err(1,"cannot select");
    if (rv == 0) {
      fprintf(stderr,"timeout\n");
    }
    // Try to read a udp message anyway.

#else
    if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,(char *)&tv,
        sizeof(struct timeval)) == -1
    ) {
      err(1,"cannot set timeout on socket");
    }
#endif

  char message[81] = { 0, };
  if (recv(sock,message,sizeof(message)-1,0) < 0) {
    err(1,"cannot receive data");
  }
  printf("message: %s\n",message);
  
  return 0;
}
#include <err.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <assert.h>
#include <unistd.h>
#include <stdio.h>

//------------------------------------------------------------------------------
int main(int argc, char *argv[]) {

  if (argc < 3 || argc > 4) {
    errx(1,"Usage: %s <data> <host> [<port>]",argv[0]);
  }
  char *data = argv[1];
  size_t size = strlen(data);
  char *hostname = argv[2];
  int port = argc > 3 ? atoi(argv[3]): 32641;
  
  // Initialize socket and daemon address
  int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (sock < 0) {
    err(1,"cannot create socket");
  }

  struct hostent *host = gethostbyname(hostname);
  if (host->h_addrtype != AF_INET) {
    errx(1,"unsupported host type %d, only IPv4 is supported",host->h_addrtype);
  }
  struct sockaddr_in daemon_address;
  memset(&daemon_address, 0, sizeof(daemon_address));
  daemon_address.sin_family = PF_INET;
  assert(host->h_length <= sizeof(daemon_address.sin_addr.s_addr));
  memcpy(&daemon_address.sin_addr.s_addr,host->h_addr,host->h_length);
  daemon_address.sin_port = htons(port);
  if (
    sendto(sock,data,size,0,
      (struct sockaddr*)&daemon_address,sizeof(daemon_address)
    ) < 0
  ) {
    err(1,"cannot send data");
  }

  close(sock);
  return 0;
}
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
RTnet-users mailing list
RTnet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rtnet-users

Reply via email to