• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            網絡服務器軟件開發/中間件開發,關注ACE/ICE/boost

            C++博客 首頁 新隨筆 聯系 聚合 管理
              152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks

            #

                   1.新建查詢語句文件query.sql,內容如下:
            --------------------------------------分割線----------------------------------------
                     use appdb;
                     set names utf8;
                     select FeedID, City , Message  from Feed limit 1000;
            --------------------------------------分割線----------------------------------------
            上面的set names utf8語句是設施當前使用的編碼,如果編碼和數據庫的編碼不一致,會出現亂碼
                  2.執行如下:
                 [root@proxy tianqg]# mysql -uroot -p < query.sql > query.txt
            回車,輸入密碼,在當前目錄下會產生查詢結果文件query.txt
                  這些語句以前都是非常熟悉的,昨天有人問起,一時沒有給出準確的回答,命令行操作這種東西是容易忘記的,還是記下來備忘吧
            posted @ 2011-01-19 09:55 true 閱讀(1417) | 評論 (0)編輯 收藏

                  有個存儲過程,功能是:根據用戶名查詢非好友的ID,代碼如下:
            begin

              select UserID  from  Users
                where
                UserID 
            != pUserID and
                Users.UserID  not 
            in
                (
                    select FriendID from Users_Friend where Users_Friend.UserID 
            = pUserID and DeleteFlag = 0
                )
                and
                Users.Name like BINARY  concat(
            '%',pUserName,'%')  ;

            end
             其中,pUserID是搜索者的UID,pUserName是要搜索的用戶名。今天發現這個存儲過程非常慢,分析結論是:not in 后面的select子查詢是每次都執行的,這出乎意料!mysql難道不能優化掉這樣的查詢嗎?
                  后來用了臨時表的方案,如下:
            begin

                Create TEMPORARY  Table  IF NOT EXISTS temp(FriendID 
            int );
                insert into temp(FriendID) select FriendID from Users_Friend where Users_Friend.UserID 
            = pUserID and DeleteFlag = 0;

                  select UserID  from  Users
                where
                UserID 
            != pUserID and
                Users.UserID  not 
            in
                (
                    select FriendID from temp
                )
                and
                Users.Name like BINARY  concat(
            '%',pUserName,'%')  ;

                drop TEMPORARY  table temp;
            end

            問題較好的解決了,因為臨時表temp中保存的都是好友的ID,非常快,不用每次都去執行好友的篩選邏輯。另外一種方式是:將好友ID作為參數傳遞到存儲過程中,在程序外面查詢好友,但要改動程序。
             
            posted @ 2011-01-13 13:05 true 閱讀(2955) | 評論 (0)編輯 收藏

                 摘要: 最近幾天一直在思考一個問題:我們需要什么樣的網絡基礎開發包?libevent,asio,ace,還是自己封裝?Buffer類,內存池  閱讀全文
            posted @ 2011-01-13 00:51 true 閱讀(3172) | 評論 (16)編輯 收藏

            已經非常的陌生了,沒有網絡幾乎寫不了代碼了,準備寫個自用的抓包工具,可以指定某個應用來抓包,這樣抓到的包分析起來更具有針對性,常用工具wireshark雖然支持過濾規則,但是對走多協議的應用,比如tcp,udp,http都用的應用過濾起來比較吃力,WPE也不太合適,我想集成一些實用小工具,如網絡字節序的轉換,UTF8和GB的轉換等,如此則可以快速分析協議,所以索性自己寫個吧,網絡抓包這塊是做服務器的基本功,已經搞定了,界面的布局和實現方面還沒有確定,不用MFC好多年,希望這次嘗試算是一個新的開始。

            posted @ 2011-01-06 23:42 true 閱讀(546) | 評論 (0)編輯 收藏

                 自從做公司的SNS社區以來,寫了不少的C#代碼,與C++相比,C#是易于使用的,開發效率提高很多倍,其中印象比較深刻的是,在一個C#工程中,可以通過向導添加配置文件,默認文件名為App.Config,是XML格式,一般內容為:
            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
                 
                
            <appSettings>

                    
            <add key="Ip" value="localhost"/>
                    
            <add key="Port" value="8888"/>
                    
            <add key="ServiceName" value="Indexer"/>


                
            </appSettings>
                
            </configuration>
            通過在appSettings里面添加add元素,即可實現通常的配置功能,更重要的是,可以進一步擴展為多級的樹形結構,與Ini格式相比,更直觀,可讀性更強,下面是基于CMarkup(http://www.firstobject.com/)的一個簡單實現:
            頭文件如下:
            #pragma once

            #include 
            <string>
            #include 
            <map>


            class AppConfig
            {
            public:
                AppConfig(
            void);
                
            ~AppConfig(void);

                
            int        GetInt(std::string key);
                std::
            string    GetString(std::string key);
            private:
                std::map
            <std::string,std::string> config_map_;
            }
            ;
             
            extern AppConfig appConfig;
            源文件如下:

            #include 
            "AppConfig.h"
            #include 
            "Markup.h"

            AppConfig appConfig;


            AppConfig::AppConfig(
            void)
            {
                CMarkup parser;
                
            if (!parser.Load( "App.Config"  ))
                
            {
                    
            return;        
                }

                
            if (parser.FindChildElem("appSettings"))
                
            {
                    parser.IntoElem();
                    
            while (parser.FindChildElem("add"))
                    
            {
                        std::
            string key = parser.GetChildAttrib("key");
                        std::
            string value = parser.GetChildAttrib("value");
                        config_map_[key] 
            = value;
                    }

                    parser.OutOfElem();
                }

                
            }


            AppConfig::
            ~AppConfig(void)
            {
            }


            int AppConfig::GetInt( std::string key )
            {
                
            if (config_map_.find(key) != config_map_.end())
                
            {
                    
            return atoi(config_map_[key].c_str());
                }

                
            else
                
            {
                    
            return 0;
                }

            }


            std::
            string AppConfig::GetString( std::string key )
            {
                
            if (config_map_.find(key) != config_map_.end())
                
            {
                    
            return config_map_[key];
                }

                
            else
                
            {
                    
            return "";
                }

            }

            測試代碼為:
            // MarkupTest.cpp : 定義控制臺應用程序的入口點。
            //

            #include 
            "stdafx.h"

            #include 
            "AppConfig.h"
            #include 
            <iostream>
            using namespace std;

            int _tmain(int argc, _TCHAR* argv[])
            {    
                cout 
            << appConfig.GetString("Ip")  << "-----" << appConfig.GetInt("Port")  << "----" << appConfig.GetString("ServiceName"<< endl;
                
            return 0;
            }


            posted @ 2010-12-29 00:25 true 閱讀(2560) | 評論 (0)編輯 收藏

                     CDR可以提供對基本數據類型如int,short,double,string等的序列化機制,簡單包裝后即可擔當RPC中的序列化角色。
            #include <iostream>
            #include 
            <string>
            #include 
            <ace/OS.h>
            #include 
            <ace/String_Base.h>
            #include 
            <ace/CDR_Stream.h>
            using namespace std;
            #pragma comment(lib,
            "aced")

            int main(int argc, char* argv[])
            {
                cout 
            << "ACE CDR demo" << endl;

                ACE_CString sAppName 
            = "CDRDemo",sAppName2;
                ACE_CDR::Long nUID 
            = 123456,nUID2;
                ACE_CDR::Float nfPosX 
            = 120.51,nfPosX2;
                ACE_CDR::Double ndScore 
            = 120.51,ndScore2;
                ACE_CString sDummy 
            = "another string",sDummy2;
                ACE_CDR::Short  nsLength 
            = 10,nsLength2;

                ACE_OutputCDR outCDR(ACE_DEFAULT_CDR_BUFSIZE);    
                
                outCDR 
            << nUID;
                outCDR 
            << nfPosX;
                outCDR 
            << ndScore;
                outCDR 
            << sAppName;//寫字符串時,先寫入字符串的長度
                outCDR << sDummy;
                outCDR 
            << nsLength;

                cout 
            << "OutputCDR size = " << outCDR.length() << endl;

                
            //可以通過socket發送出去,而在服務端進行下面的解析
                
            //1.ACE_Message_Block *ACE_OutputCDR::begin (void)
                
            //2.通過ACE_SOCK_Stream發送出去    

                ACE_InputCDR inCDR(outCDR);

                inCDR 
            >> nUID2;
                inCDR 
            >> nfPosX2;
                inCDR 
            >> ndScore2;
                inCDR 
            >> sAppName2;
                inCDR 
            >> sDummy2;
                inCDR 
            >> nsLength2;
                    

                ACE_ASSERT(nUID 
            == nUID2);
                ACE_ASSERT(nfPosX 
            == nfPosX2);
                ACE_ASSERT(ndScore 
            == ndScore2);
                ACE_ASSERT(sAppName 
            == sAppName2);
                ACE_ASSERT(sDummy 
            == sDummy2);
                ACE_ASSERT(nsLength 
            == nsLength2);

                cout 
            << "test ok." << endl;

                
            return 0;
            }

            假若有如下的demo.idl,內容如下:

                  struct user_info
                  {
                        int user_id;
                        string user_name;            
                  }
            利用idl_gen生成代碼時:
                  (1)如果是侵入式的方案,則生成user_info類時,自動添加成員OutputCDR和InputCDR成員,并添加pack(ACE_Message_Block &* msg)和parse(ACE_Message_Block * msg)成員函數,在pack和parse里面,調到對于的CDR類,按照類中數據成員的聲明順序依次序列化,反序列化
                  (2)如果是非侵入式方案,則生成user_info類時,生成獨立函數的pack(user_info& info, ACE_Message_Block &* msg)和parse(user_info& info,ACE_Message_Block * msg),pack和parse的函數實現同上
            posted @ 2010-12-26 09:52 true 閱讀(3230) | 評論 (2)編輯 收藏

                  wireshark(http://www.wireshark.org/)是我經常用到的抓包工具,這對于網絡程序的調試至關重要,特別是客戶端人員和服務端人員都認為自己的代碼沒問題時,wireshark本身是開源的,在windows平臺下基于 winpcap(http://www.winpcap.org/)開發的,安裝wireshark的時候,會提示在線安裝winpcap,今天在筆記本上用VS2008,編譯了Examples-pcap下面的basic_dump和basic_dump_ex,不曾想到的是抓不到包,甚是奇怪,因為用wireshark抓包是可以的,因此懷疑是不是哪個參數設施不對,終于比對wireshark,得出結論:將pcap_open_live的第四個參數設為0,即不能打開混雜模式,

            if ((adhandle= pcap_open_live(d->name, // name of the device
                    65536,   // portion of the packet to capture.
                       // 65536 grants that the whole packet will be captured on all the MACs.
                    0,    // promiscuous mode (nonzero means promiscuous)
                    1000,   // read timeout
                    errbuf   // error buffer
                    )) == NULL)
             {
              fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
              /* Free the device list */
              pcap_freealldevs(alldevs);
              return -1;
             }
            posted @ 2010-12-22 21:59 true 閱讀(4334) | 評論 (3)編輯 收藏

               手冊上的說明:
               

               UNIX_TIMESTAMP(), UNIX_TIMESTAMP(date)

            If called with no argument, returns a Unix timestamp (seconds since '1970-01-01 00:00:00' UTC) as an unsigned integer. If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' UTC. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD. The server interprets date as a value in the current time zone and converts it to an internal value in UTC. Clients can set their time zone as described in Section 5.11.8, “MySQL Server Time Zone Support”.


                  這里的UNIX_TIMESTAMP()的返回值和C函數time(NULL)的返回值含義一樣,
              mysql> select UNIX_TIMESTAMP();
            +------------------+
            | UNIX_TIMESTAMP() |
            +------------------+
            |       1292815556 |
            +------------------+
            1 row in set

            mysql> select FROM_UNIXTIME(1292815556);
            +---------------------------+
            | FROM_UNIXTIME(1292815556) |
            +---------------------------+
            | 2010-12-20 11:25:56       |
            +---------------------------+
            1 row in set

            posted @ 2010-12-20 12:01 true 閱讀(485) | 評論 (0)編輯 收藏


            終于碰到這個問題了,原文鏈接:http://hi.baidu.com/zzy_cqok/blog/item/46ee33998777f3056f068c2b.html

            vs2008調試后控制臺窗口關不了2010-07-29 16:19
            最近用Visual Studio 2008 寫一些控制臺程序,調試后的時候,當走到完成的時候,這個控制臺程序的窗口就關不了了。再調試的時候就會出現一個新的控制臺程序。
            在任務管理器還可以看到這個窗口,但是關不掉了。感覺這個控制臺程序已經失控了。
            雖然這個對電腦運行沒有影響,但還是很不爽。而且最后關機還有問題,導致不能關機。
            找到一些相關的網頁也討論的,最后結論是windows的一個更新KB978037導致cress.exe出了一些問題。
            解決辦法:刪除KB978037更新,刪除的辦法是在控制面板的添加或刪除程序面板里,勾選顯示更新,找到KB978037更新,刪除。
            附別人的討論記錄:http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e6d4a4f5-7002-401a-90e1-6174d7f9e3ca/
             
            posted @ 2010-12-12 13:16 true 閱讀(1108) | 評論 (0)編輯 收藏

            http://www.boostpro.com/download/
            目前只有windows平臺的,而且是32位
            posted @ 2010-12-06 12:08 true 閱讀(435) | 評論 (0)編輯 收藏

            僅列出標題
            共15頁: 1 2 3 4 5 6 7 8 9 Last 
            99久久国产主播综合精品| 国产精品99久久精品爆乳| 97久久国产综合精品女不卡| 亚洲精品乱码久久久久久蜜桃图片 | 久久99国产精品久久久 | 激情久久久久久久久久| 久久99热这里只有精品国产| 亚洲伊人久久综合影院| 久久久综合九色合综国产| 亚洲а∨天堂久久精品9966| 69久久夜色精品国产69| 色婷婷噜噜久久国产精品12p| 久久丫精品国产亚洲av| 国产精品伊人久久伊人电影| 色偷偷88888欧美精品久久久| 久久亚洲国产成人影院网站 | 国产午夜电影久久| 亚洲精品无码久久久久sm| 久久99亚洲综合精品首页| 国产精品女同久久久久电影院| 亚洲AV伊人久久青青草原| 国产精品青草久久久久福利99| 国产精品无码久久综合 | 国产一区二区三精品久久久无广告| 成人综合久久精品色婷婷 | 国产亚洲精品久久久久秋霞| 久久精品国产亚洲Aⅴ香蕉| 国产精品一区二区久久| 久久亚洲精精品中文字幕| 7777精品久久久大香线蕉| 久久精品极品盛宴观看| 午夜福利91久久福利| 亚洲国产小视频精品久久久三级| 狠狠人妻久久久久久综合| 国产精品内射久久久久欢欢| 国产一区二区三区久久精品| 久久99久久99精品免视看动漫| 久久久久人妻精品一区| 亚洲第一极品精品无码久久| 麻豆av久久av盛宴av| 无码人妻久久一区二区三区|