Cã®ã¨ã©ã¼ãã³ããªã³ã°ã¨ä¾å¤è¨è¨ãä¾å¤å¦çã®ã¡ã¢
äºåäºæ¥åçä¹±ã6æ¥ç®(ã®å...orz)ã®è¨äº
Cã®ã¨ã©ã¼ãã³ããªã³ã°ãæ¯åããã®ã¯é¢åã ï¼
ååãè¨ã£ãããCã§ã¯ã¨ã©ã¼ãã³ããªã³ã°ã«æ»ãå¤ã¨errnoãç¨ããï¼
ããã¯ããã¨ä¾å¤è¨è¨ã«ããã¦"ç¡è¦"ã¯å¤§ç½ªã§ããï¼
ã ãããé¢æ°ãå¼ã³åºãããæ»ãå¤ã¯æ¼ããããã§ãã¯ãã¹ãã ï¼
ã¨ãããã¨ã§ãä¾ãã°ä»¥ä¸ã®ããã«éä¸æ»ãå¤ããã§ãã¯ããï¼
if(send(sockfd, buf, len, 0) < 0){ ERROR("send"); exit(1); }
ãããé¢åã ï¼
ä¸ä½ã³ã¼ãã®ã©ã®é¨åãæ£å¸¸ç³»ã®å¦çãªã®ãï¼
ã»ã¨ãã©ã¨ã©ã¼ãã³ããªã³ã°*1ã§åãå°½ãããããããªããï¼
ããããã¨ã©ã¼ãã³ããªã³ã°é¨åã«æ¸ãã®ã¯æ¯ååãã³ã¼ãã ããã³ã¼ãã®ç¹°ãè¿ãã¯é²ãããï¼
ã¨ã©ã¼å¦çé¨åãã©ããã³ã°ãã¦æ¥½ããã
unpv12eã®ä¸ã§ã©ããã¼ã被ãããã¨ã«ãã£ã¦ãã®é¢åãåé¿ããæ¹æ³ãç¥ã£ãï¼
int Socket(int family, int type, int protocol) { int n; if ( (n = socket(family, type, protocol)) < 0) err_sys("socket error"); return(n); }
åæ¸ã§ã¯ãä¸è²«ãã¦ä¸è¨ã®ããã«å¤§æåã§å§ã¾ãé¢æ°åãã©ããã¼é¢æ°ã¨ãã¦ãå°æåã§å§ã¾ãåãååã®é¢æ°ãå¼ã³åºãï¼
ããã«ååè¨äºã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ãåãããã«ããã°ãæ»ãå¤ã®ãã§ãã¯ãããªãã¦è¯ãããã©ãã§ã¨ã©ã¼ãèµ·ãã£ããããã°ããä¸ç®çç¶ã«ãªãã¨èããã®ã§ãä¸è¨ã®ã³ã¼ãã(socket(2)ãããªãã¦send(2)ã ãã©)å°ãæ¡å¼µããï¼
send(2)ã®ã©ããã¼é¢æ°ã¨ãã¯ãå®ç¾©
ãããã«ä¸è¨ã®ãã¯ãã¨ã©ããã¼é¢æ°ã®ãããã¿ã¤ã宣è¨ãä»è¾¼ãã§ããã°ãsendãå¿
è¦ãªç®æã§ã¯åã«Send(sockfd, buf, len, 0);
ã¨æ¸ãã ãã§è¯ãï¼
ããã¯æ¥½ã§ããï¼ãããèªã¿ãããï¼fopenãfgetsãªã©ã®é¢æ°ãã©ããã³ã°ããªããªãprintfãã©ããã³ã°ãã¦ãè¯ãï¼
unpv12e(p12)ã«ãã
ã©ããã¼é¢æ°ã®ä»æ§ã«ã¯ãcloseãlistenãªã©ãæ®æ®µã¨ã©ã¼ç¶æ ãç¡è¦ããã¦ãã¾ãé¢æ°ã®ã¨ã©ã¼ãæ¤æ»ã§ããã¨ãããæã¾ããå¯ä½ç¨ãããï¼
ã¨ããã§ã¯ãªããï¼ç´ æ´ããã*2ï¼
ãããæ§ã§ã³ã¼ãã¯æ£å¸¸ç³»ã®å¦çã®ã¿ãè¨è¿°ãããã£ãããããã®ã«ãªã£ãï¼ãã§ããããã§ããï¼
â»ãã ããã¨ã©ã¼çºçæã«å³åº§ã«ããã»ã¹ãçµäºããå ´åã«éã
æ£å¸¸ç³»ãæºæ£å¸¸ç³»ãç°å¸¸ç³»
unpv12e(p12)ã«ã¯ããã«ä»¥ä¸ã®æ§ãªè¨è¿°ãããï¼
æ¬æ¸ã®æ®ãã®é¨åã§ã¯ãæ示çãªã¨ã©ã¼ã®æ¤æ»ã¨ããã»ã¹ãçµäºããã以å¤ã®ã¨ã©ã¼å¦çãå¿ è¦ãªå ´åãé¤ãã¦ããããã®ã©ããã¼é¢æ°ã使ç¨ããï¼
åã«ã¨ã©ã¼ãèµ·ããã°çµäºããã°è¯ãã³ã¼ããæ¸ãã¦ãããã¡ã¯æ°æ¥½ã ã£ãããããã»ã¹ãçµäºããã以å¤ã®ã¨ã©ã¼å¦çãå¿ è¦ãªå ´åã®ãããªç¶æ³ã«ã¶ã¡å½ãã£ãç¬éãã¨ã©ã¼å¦çãã¨ãã§ããªãæ©ã¾ãããã®ã«ãªã£ã¦ãã¾ã£ãï¼
ä¸ã«æããsend(2)ã¯ãæåããå ´åãéä¿¡ããããã¤ãæ°ãè¿ãããã¨ã©ã¼ã®å ´åã-1ãè¿ããerrnoãé©åã«è¨å®ããï¼
ããã°ã©ãã¯ã¨ã©ã¼ã®åå ã«å¿ãã¦ããã»ã¹ãçµäºããããé©åãªã¨ã©ã¼å¦çãè¡ã£ãä¸ã§å¦çã復帰ãããå¤æããªããã°ãªããªãï¼
極端ãªãã¨ãè¨ãã°ãéä¿¡éä¸ã«ã³ãã¯ã·ã§ã³ãåããå ´åã¯ç°å¸¸ç³»ãï¼æºæ£å¸¸ç³»ãï¼ã¿ã¤ã ã¢ã¦ããèµ·ãã£ããããã¯ç°å¸¸ç³»ãï¼æºæ£å¸¸ç³»ãï¼ãªã©ããã¡ãã¡å¤æããªããã°ãªããªãï¼
æ»ã¬ã¹ããã®ãçããã¦ã¯ãªããªãããæºæ£å¸¸ç³»ãªãã°å¼ã³åºãå ã§å¯¾å¦ããã¨ããã®ã¯ãå¼ã³åºãå ã§ä¸éå端ã«ãªã£ãå¦çãå·»ãæ»ãå¦çãå¿ è¦ã«ãªã£ããã¨ãããï¼
ããã¦ä½ãæºæ£å¸¸ç³»ãªã®ãã¯ã¢ããªã±ã¼ã·ã§ã³ã®è¦ä»¶æ¬¡ç¬¬ã§ããï¼
ä¾ãã°ããµã¼ãããã°ã©ã ã«ã¯ã©ã¤ã¢ã³ãããã®ã¢ã¯ã»ã¹ãéä¸ãããã¦ãfopen(3)ãaccept(2)ã§ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ä¸è¶³ã«é¥ã£ããã¨ãããï¼
ãã®ãããªç¶æ³ã«é¥ã£ã¦åãã¦ããããããã¨æã£ãããå®éã«ãããªåé¡ãèµ·ããã¾ã§ã¯èªåã®ä¸ã§ã¯ç¹ã«åé¡ã®ãªãã³ã¼ãã ã£ãï¼
ãããªããã¼ããªãä¾ã ã¨æ³ååã足ããªãã¨è¨ããã¦ãã¾ãããã ãã©ããã£ã¨è¤éãªäºè±¡ã ã¨äºæ¸¬ãé£ãããã ãããã®è¾ºã¯å£®çµ¶ã«çµé¨ãçãããå ´é¢ã§ãããããªæ°ãããï¼
æå ã®ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãã³ãã¯ã·ã§ã³ãã¿ã¤ã ã¢ã¦ããã¦ãã¾ãåã«ãã¡ã¤ã«ãéãããã£ãã®ã§ã以ä¸ã®ããã«ãã£ã¹ã¯ãªãã¿ä¸è¶³ã§ãã¡ã¤ã«ãéããªãå ´åã¯ããã°ããå¾ ã£ã¦å度ãã¡ã¤ã«ãªã¼ãã³ã試ã¿ãããã«ãã.
FILE * fopen_safefd(const char *filename, const char *mode) { FILE *fp = NULL; while(1) { fp = fopen(filename, mode); if(fp != NULL) { break; //ãã¡ã¤ã«ãªã¼ãã³æå } else if(errno == EMFILE) { //ãã£ã¹ã¯ãªãã¿ä¸è¶³ WARNNING("file=%s", filename); sleep(1+rand()/((double)RAND_MAX+1.0)); //ãã£ã¹ã¯ãªãã¿ã空ãã®ãå¾ ã¤1+(0~1)ç§ errno = 0; } else { ERROR("fopen failed:file=%s", filename); exit(1); } } return(fp); }
ãªãããããã¦è¦ãã¨æ¾ç½®ãã¦ããåé¡ãå±±ã»ã©ãããããªâ¦ï¼
ã»æºæ£å¸¸ç³»ã¯å¼ã³åºãå ã§å¯¾å¦ããã¨ããè¦å¾ãç¡è¦ãã¦ããï¼
ã»å¾ ã¡æéã®1+(0~1)ç§ã¨ããæéã«æ確ãªæ ¹æ ããªãï¼
ã»ãã¡ã¤ã«ãéããã¾ã§ãã¤ã¾ã§ããªã¼ãã³ãç¹°ãè¿ãåé¡ãæã£ã¦ããï¼
åè:ã¨ã©ã¼å¦çã®æ½è±¡å#46
ã¾ãããªããè¨è¨ã®æ®µéã§æºæ£å¸¸ç³»ãèæ ®ã«å ¥ãã¦ãããªãã¨APIè¨è¨ãå¦ãªãã¨ã«ãªããã¨ããªãã¨ãªãããã£ã¦ããï¼
ä¾å¤è¨è¨ã¨ããã®ã¯ã©ãããæ³å以ä¸ã«é£ãããããï¼
ä¾å¤å¦çã®è©±ã¨ããLOG.debug("nice catch!")ã¨ã
åå°½ããã®ã§å¾ã¯æ¸ããã¨æã£ã¦ãããã¨ã®ã¡ã¢æ¸ãï¼
çºçããã¨ã©ã¼ãæºæ£å¸¸ç³»ã ã£ãå ´åãå¼ã³åºãå ã«ã¨ã©ã¼ãä¼æãããå¿ è¦ãããããé¢æ°å¼ã³åºãããã¹ãããå ´åã«ãã®å´åãå端ãããªãï¼
âãããããã¦ä¾å¤å¦çã¯ãã®è¾ºããçã¾ããï¼
ä¾å¤ã¯ãæ·±ãé層ã§çºçããã¨ã©ã¼ãä¸ä½å±¤ã§ãã³ããªã³ã°ããããã«ãã¨ã©ã¼å¤ãä¼æ¬ãã¦ããã®ãæéã§ããã¨ããåæ©ã®å ã«å°å ¥ãããã ã¨ã©ã¼ãã³ããªã³ã°ã«é¢ããèã
âãããããã°ããã³ã¼ãã£ã³ã°ãæ¯ããæè¡ãã§ã¯ã"失æãããã¸ã£ã³ããã"ã¨ããçºæ³ãCè¨èªããããã£ã¨åã®è¨èªãããã£ãã¨ãã話ãèµ·ç¹ã«ãä¾å¤å¦çã®æ´å²ãUNIVAC I, COBOL, PL/I,CLU,C++,Windows NT 3.1, Dè¨èª, Python, Ruby, JavaScript, Java, C#ã¨ãã£ãè¨èªã®è¨è¨ææ³çã交ãã¦è°è«ããã¦ããï¼
ãããè¯ãããã«è¦ããJavaã®æ¤æ»ä¾å¤ãä½æ æµè¡ããªãã®ãã¨ãã話ãé¢ç½ãï¼æ°ãããä¸è¨ã§è¨ã£ã¦ãã¾ãã°ãé¢åãããããã§ãããï¼ã
ã¡ãªã¿ã«Linuxã«ã¼ãã«ã§ã¯ä¾å¤å¦ç(ãªã½ã¼ã¹å¦ç)ã«ãããå¦çãgotoæã§è¡ã£ã¦ãããããï¼
- ä½è : 西尾泰å
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/04/24
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- ãã®ååãå«ãããã° (27件) ãè¦ã
âãä¾å¤å¦çããã¾ãã¾ãªè¨èªã§æ¡ç¨ãããä¸æ¹ã§Googleã®ã³ã¼ãã£ã³ã°è¦ç´ã§ã¯C++ã§ä¾å¤ä½¿ããªã¨ããã話ãããï¼
ã¨ã©ã¼å¦çã®æ½è±¡å#26
âã確ãã«ä¾å¤å¦çãæå¼·ã§ããã¨ä¸ã®ä¸çã«æºå ´ä¸è´ãã¦ãªãã£ã½ãä¾ã¨ãã¦Goè¨èªã®ã¿ãã«ã«ããã¨ã©ã¼ãã³ããªã³ã°æ©æ§ï¼Goã®ã¿ãã«ã¯è¨èªçµã¿è¾¼ã¿ãã¤ã¨ã©ã¼ãç¡è¦ãã«ãããããï¼
âãããã¾ã§ããã¤ãã¹ã©ã¤ãã®ãªã³ã¯ãå¼µã£ã¦ãããã©ãã¨ã©ã¼ãã³ããªã³ã°ã¨ä¾å¤è¨è¨ã«ã¤ãã¦åãåèã«ãªã£ãä¾å¤ã¨ãã®ã³ã°åå¼·ä¼ã¨ãããã®ã2012/6/27ã«è¡ããã¦ããã®ã§ã¡ã¢ï¼ã ãã¶æåã£ã½ããã©ï¼
åè:
ä¾å¤è¨è¨ã«ããã大罪
java-jaãLOG.debug("nice catch!")ãã«åå ãã¦ãã - Shinyaâs Daily Report (æä¸é¨ã«ä»ã®ããã°ãã¹ã©ã¤ãã®ãªã³ã¯ãããã¾ã)
java-ja ã®ä¾å¤ã¨ãã®ã³ã°åå¼·ä¼ã§çºè¡¨ãã¦ãã¾ãã - ç´ç²é¢æ°ç©ºé
java-jaã§ä¾å¤å¦çã®è©±ããã¦ãã¾ãã - 西尾泰åã®ã¯ã¦ãªãã¤ã¢ãªã¼
â»ä¾å¤è¨è¨ãä¾å¤å¦çã®æ¯éã«ã¤ãã¦ã¯çµæ§æè¦ãåãããã¨ããã¿ãããªã®ã§ãã¡ããã¨ç¥ãããå ´åã¯ãªã³ã¯å ã®ããã°çãè¦ã¦ã¿ãã¨è¯ãã¨æãã¾ãï¼
ãã®ä»åè:
æºæ£å¸¸ç³»ã¨ç°å¸¸ç³»ã¸ã®å¯¾å¿
ã¨ã©ã¼ãã³ããªã³ã°ã«é¢ããèã
ããµã«ãªæãã¦ä¸ããï¼
ã¨ããããã§ã風åæ·åºãããã¦å¾åã¯ããä½ãè¨ãããã®ããè¯ãããããªããªã£ãã®ã§ãã¿ã¤ãã«ã«ã¡ã¢ã¨æ¸ãã¦éèµ°ï¼
ããã°é£ããï¼
ééã£ããã¨è¨ã£ã¦ããããµã«ãªæãã¦ä¸ããï¼
*1:ããã§ä¾å¤å¦çã¨ããã¨èª¤è§£ãçããããã«ãã¨ã©ã¼ãã³ããªã³ã°ã¨ãã¨ã©ã¼å¦çãªã©ã¨è¡¨ç¾ãã¦ããã®ã§ãããä¸æ¹ã§ä¾å¤å¦çã¨ããè¨èãä¸è¬ã«çãªæå³ã§è§£èª¬ããã¦ããããã¦ãæ¬å½ã«æ¥æ¬èªã£ã¦é£ããã§ãï¼
*2:ã¶ã£ã¡ããç¾å¨ãããã§è¯ãã¨ããã¦ããã®ã§ããããï¼ãä»æãããªå¤ãæ¸ç±ã®ã³ã¼ãã£ã³ã°ã¹ã¿ã¤ã«ãå¦ä¿¡ãã¦ããªãã¦ããã§ãã奴ã ãªï¼ãã¨ããæããªãã§ããããï¼ãªã©ã¨ããå¿é äºã¯å°½ããªãã®ã§ãããããã¯ãã¦ãã