Waiting for the wind

programming memo in different platforms

「network programming」分類文章彙整

setsockopt SO_LINGER

發文作者 cotton5415 於 十月 30, 2009

SO_LINGER:
只針對 socket 的 close() 發揮作用。
case 1 (default):
linger->l_onoff = 0; –> linger->l_linger no effect;
case 2:
linger->l_onoff !=0; linger->l_linger = 0 ;
close() immediately. 不管底層的資料是否送出,直接送一個 RST(reset)給另一端。因此另一端在 recv的時候,會產生 ECONNRESET 的 error

case 3:
linger->l_onff != 0; linger->l_linger != 0;
close() 會 block住或是等到 l_linger 的timeout時間到之後,產生 EWOULDBLOCK error

ref: http://www.developerweb.net/forum/archive/index.php/t-2982.html

發表於 Debian's Road, network programming, web programming | 已加上的標籤: , , | 張貼留言 »

redirect stdout to a file

發文作者 cotton5415 於 五月 31, 2008

FILE * fp = fopen(“myfile.txt","w+a") ;
int fd= -1;
if ( fp != NULL ) dup2(fd,1) ; // 1 for stdout
if ( fd < 0 ) return false ; // fail
else return true ; // success
close(fd);
fclose(fp);

發表於 Debian's Road, eee pc's road, Embedded system's Road, MAC OS X's Road, network programming | 張貼留言 »

stray ‘\’ in program

發文作者 cotton5415 於 九月 13, 2007

problem
compiling error:

mmi_gfx_macro.h:21: parse error before `{‘
mmi_gfx_macro.h:21: stray ‘\’ in program
mmi_gfx_macro.h:22: stray ‘\’ in program

root cause
Possibly \ at “end" of a CRLF terminated line is not seen as
line-continued?
solution:
%dos2unix <your_c_file>

發表於 Debian's Road, Embedded system's Road, Fedora Core 6's Road, MAC OS X's Road, network programming, networking | 張貼留言 »

select block poblem

發文作者 cotton5415 於 九月 5, 2007

solve IR controller blocking problem

int init_irdev(const char *fname)
{
unsigned long val;
unsigned long rptkey[] = {8,
IR_KEY_ARROW_UP,
IR_KEY_ARROW_DOWN,
IR_KEY_ARROW_RIGHT,
IR_KEY_ARROW_LEFT,
IR_KEY_MOUSE_UP,
IR_KEY_MOUSE_LEFT,
IR_KEY_MOUSE_DOWN,
IR_KEY_MOUSE_RIGHT
};

fd_irkey=open(“/dev/ir", O_RDONLY| O_NONBLOCK );
//fd_irkey=open(fname, O_NONBLOCK);

if (fd_irkey <0 ){
fprintf(stderr,"init_irdev(): Can’t opening %s.\n",fname);
return -1;
}

if( ioctl(fd_irkey,IR_IOCSETREPEATKEYS, rptkey))
{
close (fd_irkey);
fprintf(stderr,"init_irdev(): can’t set repeat.\n");
return -1;
}

val = 0;
if(ioctl(fd_irkey,IR_IOCSETWAITPERIOD, &val)){
close (fd_irkey);
fprintf(stderr,"init_irdev(): can’t set wait period.\n");
return -1;
}

val = 1;
if(ioctl(fd_irkey,IR_IOCSETLOOPCOUNT, &val)){
close (fd_irkey);
fprintf(stderr,"init_irdev(): Can’t set loop count.\n");
return -1;
}

return fd_irkey;
}

FD_ZERO(&copyfds);
FD_SET(awibm->fd_ir, &copyfds);
if( select(maxfd +1, &readfds, NULL, NULL, &tv) > 0)

man select to get the return value and man open to get the information about O_NONBLOCK flag setting

發表於 Debian's Road, Fedora Core 6's Road, network programming | 張貼留言 »

non-blocking I/O

發文作者 cotton5415 於 四月 13, 2007

IBM reference

發表於 network programming | 張貼留言 »

 
Follow

Get every new post delivered to your Inbox.