This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Prototyping with the synthetic target.
- From: Wouter Cloetens <wouter at mind dot be>
- To: ecos-discuss at sources dot redhat dot com
- Date: Fri, 2 Aug 2002 00:18:52 +0200
- Subject: Re: [ECOS] Prototyping with the synthetic target.
- References: <F626113795D3EB4482E5ACFBD934651234C66B@mailhost.stratalight.com> <3D40FE8E.A92D859E@ascom.ch> <3D45981F.D75077F7@lbl.gov> <20020730071922.GB3295@biferten.ma.tech.ascom.ch> <3D496F72.2952EF71@lbl.gov>
- Reply-to: ecos-discuss at sources dot redhat dot com
On Thu, Aug 01, 2002 at 10:27:14AM -0700, Chuck McParland wrote:
> You mentioned using sockets at the hal_sys level. I assume you
> had to link with the Linux libraries to get the socket calls. Wouldn't this
> cause conflicts with the ecos synthetic lib?
What I did was to use the socketcall system call directly. It's a single
system call that provides all the socket call services. See the linux
kernel source, net/socket.c, and include/linux/net.h for the identifier
values of the socket calls.
Here's a sample implementation of a few calls:
#define SYS_SOCKET 1 /* sys_socket(2) */
#define SYS_BIND 2 /* sys_bind(2) */
externC unsigned long cyg_hal_sys_socketcall(int call, unsigned long
*args);
static inline int machdep_socket(int domain, int type, int protocol)
{
unsigned long args[3];
args[0] = domain;
args[1] = type;
args[2] = protocol;
return cyg_hal_sys_socketcall(SYS_SOCKET, (unsigned long *)&args);
}
static inline int machdep_bind(int sockfd, struct sockaddr *my_addr,
socklen_t addrlen)
{
unsigned long args[3];
args[0] = sockfd;
args[1] = (unsigned long)my_addr;
args[2] = (unsigned long)addrlen;
return cyg_hal_sys_socketcall(SYS_BIND, (unsigned long *)&args);
}
Instead of returning -1 and placing the error code in errno, the calls
return the negative error code.
Another thing you need to keep in mind when making calls in the synthetic
Linux target, is that the scheduler seems to be signal driven. This
means that any blocking system call is extremely likely to be
interrupted, and return -EINTR. Shield that, like this:
static int internal_send(int s, const void *data, size_t len, int flags)
{
int err;
while (1)
{
err = machdep_send(s, data, len, flags);
if (err == -EAGAIN)
{
cyg_thread_delay(100);
cyg_thread_yield();
continue;
}
else if (err == -EINTR)
continue;
else
break;
}
return err;
}
Hope to have helped out.
bfn, Wouter
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss