Monday, October 20, 2008

Communication over ethernet mac layer without TCP/IP part 1

I use two different o.s. at a embedded system. Altohough, there are so many solutations such as broadcast, IP sockets, non-reliable IP-less protocol and so on, but they can not meet our requerments.

Here are my concept:
A protocol must base on ethernet layer II and has capability to do TCP-friendly stuff. The requerments are below:
  • Can set or get system parameter between A and B.
  • This protocol must be extendable from dual systems to multiple systems.
  • It can not fix at client and server mode. These two (or more) system can be client and server at the same time.
  • We can transfer large file or multipart request/response over a transaction. And the upper layer applications do not have to worry about fragmentations.
  • This protocol must provide Event/Notify. A could register events which is occurred at B. After registation, B must send notify while some events happened.
Here are issues:
  1. How to define session and transations?
  2. How to encoding payload ?
  3. How to implement re-transmit ?
  4. others

Tuesday, October 14, 2008

Change pipe to non-blocking mode

The default pipe(...) is one blocking fd. If you need non-blocking IO, you can refer fowling sample code:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(void) {
int fd[2], pipeAttr;
/*fd[0] for reader, fd[1] for writer*/
pipe(fd);
fnctl(fd[0], pipeAttr, F_GETFL);
pipeAttr |= O_NONBLOCK;
fnctl(fd[0], F_SETFL,
pipeAttr);
do_something(fd);
close(fd[0]);
close(fd[1]);
}
viod do_something(int fd[]) {
/*......*/
}

Zombie while create child thread

I use pthread_create(...) to generate child thread. The child thread becomes zombie after I termite program. After some "google" pages, the answer comes out: join child thread at main process.

errno.h

If you want to use errno at c program, you must include errno.h not declare "extern int errno".

char *strerror(int) is used to display error text.

There are two related header files at kernel source directory:
include/$(ARCH)/errno.h
asm-generic/errno-base.h