This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Prototyping with the synthetic target.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]