2008-03-15から1日間の記事一覧

echod_f: 標準入出力関数を使ってechoサーバ

recv(2)、send(2)を使わない。fdopenしたときに、close/fcloseの両方呼び出すべきなのかどうか、はっきりしないなぁ。 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <arpa/inet.h> #include <sys/types.h> #include <unistd.h> #include <errno.h> #define ECHO_PORT 7 #define MAX_BACKLOG 5 #define</errno.h></unistd.h></sys/types.h></arpa/inet.h></sys/socket.h></string.h></stdlib.h></stdio.h>…

WinSock: socketにfgetsを使えない… と思ったら出来た

_open_osfhandleしてfdopenすれば使えると思ったのに。 追ってみると、ReadFileでコケてるみたい。 ひょっとしてサーバ側だと使えないのかな?うーん… socketじゃなくてWSASocketを使ったらできた! #include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> #include <io.h> #include <fcntl.h> #inc</fcntl.h></io.h></stdio.h></ws2tcpip.h></winsock2.h>…

libevを使った低パフォーマンスなCOMETサーバ(試作)

「これはひどい」だ…orz。 my_commetd.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <alloca.h> #include <sys/socket.h> #include <arpa/inet.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <ev.h> #define PORT 10080 #define MAX_BACKLOG 5 #define …</ev.h></errno.h></fcntl.h></unistd.h></sys/types.h></arpa/inet.h></sys/socket.h></alloca.h></string.h></stdlib.h></stdio.h>