Pipe is a worm hole connecting C and C++
In C programming language, the observer design pattern is implemented with function pointer (aka callback function). But in Qt library, it introduces signal and slot. How to link a callback function from the C callback function to the C++ siganl and slot is a problem I encounter. Call back function can only be static, but signal and slot can not. There are some triky way to pretend a non-static function to a static function. But the easiest way is to use pipe. the callback function create a pipe and do the read operation, while the siganl function wait for and read at the other end of the pipe.
The pipe is like a worm hole connecting C and C++, two different time and space. How cool!
Ïà¹ØÎĵµ£º
1¡¢ ¾³£¿´¼ûreturn EXIT_SUCCESS»òreturn EXIT_FAILURE£¬µ«¶¼²»ÖªÕâÁ½¸öÀ´×Ժ䦣¬ÏÖÔÚ²ÅÖªÔÀ´stdlib.h¶¨ÒåÁËEXIT_SUCCESSºÍEXIT_FAILURE·ûºÅ¡£
ÔÚstdlib.hÍ·ÎļþÀ
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
& ......
תÖÁhttp://www.pconline.com.cn/pcedu/empolder/gj/c/0503/566020.html
º¯Êý´æ·ÅÔÚÄÚ´æµÄ´úÂëÇøÓòÄÚ£¬ËüÃÇͬÑùÓеØÖ·£¬ÎÒÃÇÈçºÎÄÜ»ñµÃº¯ÊýµÄµØÖ·ÄØ£¿
¡¡¡¡Èç¹ûÎÒÃÇÓÐÒ»¸öint test(int a)µÄº¯Êý£¬ÄÇô£¬ËüµÄµØÖ·¾ÍÊǺ¯ÊýµÄÃû×Ö£¬ÕâÒ»µãÈçͬÊý×éÒ»Ñù£¬Êý×éµÄÃû×Ö¾ÍÊÇÊý×éµÄÆðʼµØÖ·¡£
¡¡¡¡¶¨ÒåÒ»¸öÖ¸Ïòº¯ÊýµÄÖ¸ÕëÓÃÈçÏ ......
1¡¢¾Ö²¿±äÁ¿ÄÜ·ñºÍÈ«¾Ö±äÁ¿ÖØÃû£¿ ¡¡
¡¡´ð£ºÄÜ£¬¾Ö²¿»áÆÁ±ÎÈ«¾Ö¡£ÒªÓÃÈ«¾Ö±äÁ¿£¬ÐèҪʹÓÃ"::" ;¾Ö²¿±äÁ¿¿ÉÒÔÓëÈ«¾Ö±äÁ¿Í¬Ãû£¬ÔÚº¯ÊýÄÚÒýÓÃÕâ¸ö±äÁ¿Ê±£¬»áÓõ½Í¬ÃûµÄ¾Ö²¿±äÁ¿£¬¶ø²»»áÓõ½È«¾Ö±äÁ¿¡£¶ÔÓÚÓÐЩ±àÒëÆ÷¶øÑÔ£¬ÔÚͬһ¸öº¯ÊýÄÚ¿ÉÒÔ¶¨Òå¶à¸öͬÃûµÄ¾Ö²¿±äÁ¿£¬±ÈÈçÔÚÁ½¸öÑ»·ÌåÄÚ¶¼¶¨ÒåÒ»¸öͬÃûµÄ¾Ö²¿±äÁ¿£¬¶øÄÇ ......
ÕâƪÈÕÖ¾»¹ÊÇÏÈ´ÓÒ»¸öÄܹ»ÔËÐÐÆðÀ´µÄÀý×Ó³ö·¢£¬Ò»µ©ÄÜ˳ÀûµÄ¿´µ½³ÌÐòµÄ³É¹¦ÔËÐУ¬ÄÇô½ÓÏÂÀ´µÄʼþÎÒÏëÓ¦¸ÃÊÇÎÊΪʲôÁË£¿ËƺõÕâÑù¸ü¼ÓÈÝÒ×Àí½âºÍÕÆÎÕ¡£
¶ÔÓÚsocket³ÌÐòµÄ¸ÅÄîÕâÀï¾Í²»¶àдÁË£¬µ«ÎÒÏàÐÅ£¬Èç¹ûÄÜ¿´ÍêÕâÕûƪÎÄÕ£¬ÎÒÏàÐŲ»»áÔÙÓÐÕâÑùµÄÒÉÎʵġ£
ÏÂÃ潫±àдһ¸öc/s½á¹¹µÄ³ÌÐò£¬Ö÷Òª¹¦ÄÜÊÇclient½«Ïòserver·¢Ë ......
¹ØÓÚº¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå
¹ØÓÚº¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå·½·¨£¬ÓÐÁ½ÖÖ£ºÒ»ÖÖÊDZê×¼µÄ·½·¨£»Ò»ÖÖÊÇÃÉÆ·¨¡£
µÚÒ»ÖÖ£¬±ê×¼·½·¨£º
{
·ÖÎö£ºº¯ÊýÖ¸ÕëÊý×éÊÇÒ»¸öÆäÔªËØÊǺ¯ÊýÖ¸ÕëµÄÊý×é¡£ÄÇôҲ¾ÍÊÇ˵£¬´ËÊý¾Ý½á¹¹ÊÇÊÇÒ»¸öÊý×飬ÇÒÆäÔªËØÊÇÒ»¸öÖ¸Ïòº¯ÊýÈë¿ÚµØÖ·µÄÖ¸Õë¡£
¸ù¾Ý·ÖÎö£ºÊ×ÏÈ˵Ã÷ÊÇÒ»¸öÊý×飺Êý×éÃû[]
Æä´Î£¬ÒªËµÃ ......