[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[plamo:25405] Re: TCP のportが解放されるとき
-
From:早間
-
Date:Sat, 30 Apr 2005 20:13:47 +0900 (JST)
- Subject: [plamo:25405] Re: TCP のportが解放されるとき
- From: 早間<hayama@xxxxxxxxxxxxx>
- Date: Sat, 30 Apr 2005 20:13:37 +0900 (JST)
早間です。
> イクバルです。
>
> 以下のプログラムですが、どいうふうに終了させますか?
> シグナルを処理する部分を見当たらないので、勝手に Ctrl-C とかをして終了させる
> ではないかな。。
>
> そうすると、while 1 のループから出ることがなくなるので、ソケットをちゃんと閉
> じないことが原因じゃないですかね。。
>
終了のキーワードを組み込んであります。
クライアントから例えば「quit」という語を送り
/^quit\s/i
で合致する場合 newsocket の処理を終了し、リターンコード 9 を返し、
sokfd も終了させます。
CTL-C での強制終了ではありません。
もし、CTL-C や kill killall ならば close や shutdown のリターンコード判定
は無意味になります。
簡単に書いたので誤解を招いたようです。もう少し書くと下記のようにな
ります。その他、select などもあるので条件を網羅することは大変です。
ノーマルにプログラムが終了していることだけ、ご理解下さい。
while (rtn != 9) {
newsocket=accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
rtn=0;
while ( rtn ==0 ) {
send (newsocket ,message ,strlen(message),0);
read(newsocket, buff, sizeof(buff) );
if (buff =~ /^quit\s/i) {rtn=9;continue;} <<--- c と perlの混在ですが
if (buff =~ /^end\s/i) {rtn=1;continue}
}
shutdown(newsocket);
if (rtn < 0){puts("shutdown error");}
close (newsocket);
if (rtn < 0 ){puts("close error");}
}
rtn=shutdown(sockfd,2);
if (rtn < 0){puts("shutdown error");}
rtn=close (sockfd);
if (rtn < 0){puts("close error");}
-- 早間 義博
メイリングリストから送られてくるメイル以外届きません。
- Follow-Ups
-
- [plamo:25407] Re: TCP のportが解放されるとき, OSAKI Yohei
- References
-
- [plamo:25403] TCP のportが解放されるとき, 早間
- [plamo:25404] Re: TCP のport が解放されるとき, Iqbal Abdullah
[検索ページ]
[メール一覧]
Plamo ML 公開システム