• <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>

            網(wǎng)絡(luò)服務(wù)器軟件開發(fā)/中間件開發(fā),關(guān)注ACE/ICE/boost

            C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks

            #

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

                  有個(gè)存儲(chǔ)過程,功能是:根據(jù)用戶名查詢非好友的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是要搜索的用戶名。今天發(fā)現(xiàn)這個(gè)存儲(chǔ)過程非常慢,分析結(jié)論是:not in 后面的select子查詢是每次都執(zhí)行的,這出乎意料!mysql難道不能優(yōu)化掉這樣的查詢嗎?
                  后來(lái)用了臨時(shí)表的方案,如下:
            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

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

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

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

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

                 自從做公司的SNS社區(qū)以來(lái),寫了不少的C#代碼,與C++相比,C#是易于使用的,開發(fā)效率提高很多倍,其中印象比較深刻的是,在一個(gè)C#工程中,可以通過向?qū)砑优渲梦募J(rèn)文件名為App.Config,是XML格式,一般內(nèi)容為:
            <?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元素,即可實(shí)現(xiàn)通常的配置功能,更重要的是,可以進(jìn)一步擴(kuò)展為多級(jí)的樹形結(jié)構(gòu),與Ini格式相比,更直觀,可讀性更強(qiáng),下面是基于CMarkup(http://www.firstobject.com/)的一個(gè)簡(jiǎn)單實(shí)現(xiàn):
            頭文件如下:
            #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 "";
                }

            }

            測(cè)試代碼為:
            // MarkupTest.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
            //

            #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 閱讀(2569) | 評(píng)論 (0)編輯 收藏

                     CDR可以提供對(duì)基本數(shù)據(jù)類型如int,short,double,string等的序列化機(jī)制,簡(jiǎn)單包裝后即可擔(dān)當(dāng)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;//寫字符串時(shí),先寫入字符串的長(zhǎng)度
                outCDR << sDummy;
                outCDR 
            << nsLength;

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

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

                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,內(nèi)容如下:

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

                  wireshark(http://www.wireshark.org/)是我經(jīng)常用到的抓包工具,這對(duì)于網(wǎng)絡(luò)程序的調(diào)試至關(guān)重要,特別是客戶端人員和服務(wù)端人員都認(rèn)為自己的代碼沒問題時(shí),wireshark本身是開源的,在windows平臺(tái)下基于 winpcap(http://www.winpcap.org/)開發(fā)的,安裝wireshark的時(shí)候,會(huì)提示在線安裝winpcap,今天在筆記本上用VS2008,編譯了Examples-pcap下面的basic_dump和basic_dump_ex,不曾想到的是抓不到包,甚是奇怪,因?yàn)橛脀ireshark抓包是可以的,因此懷疑是不是哪個(gè)參數(shù)設(shè)施不對(duì),終于比對(duì)wireshark,得出結(jié)論:將pcap_open_live的第四個(gè)參數(shù)設(shè)為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 閱讀(4342) | 評(píng)論 (3)編輯 收藏

               手冊(cè)上的說(shuō)明:
               

               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函數(shù)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 閱讀(489) | 評(píng)論 (0)編輯 收藏


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

            vs2008調(diào)試后控制臺(tái)窗口關(guān)不了2010-07-29 16:19
            最近用Visual Studio 2008 寫一些控制臺(tái)程序,調(diào)試后的時(shí)候,當(dāng)走到完成的時(shí)候,這個(gè)控制臺(tái)程序的窗口就關(guān)不了了。再調(diào)試的時(shí)候就會(huì)出現(xiàn)一個(gè)新的控制臺(tái)程序。
            在任務(wù)管理器還可以看到這個(gè)窗口,但是關(guān)不掉了。感覺這個(gè)控制臺(tái)程序已經(jīng)失控了。
            雖然這個(gè)對(duì)電腦運(yùn)行沒有影響,但還是很不爽。而且最后關(guān)機(jī)還有問題,導(dǎo)致不能關(guān)機(jī)。
            找到一些相關(guān)的網(wǎng)頁(yè)也討論的,最后結(jié)論是windows的一個(gè)更新KB978037導(dǎo)致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 閱讀(1115) | 評(píng)論 (0)編輯 收藏

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

            僅列出標(biāo)題
            共15頁(yè): 1 2 3 4 5 6 7 8 9 Last 
            久久久久亚洲AV无码专区网站 | 伊人久久精品无码av一区| 久久久久久久久久久免费精品| 亚洲欧洲精品成人久久奇米网| 亚洲Av无码国产情品久久| 欧美黑人激情性久久| 国产女人aaa级久久久级| 久久亚洲AV无码精品色午夜| 久久久精品国产sm调教网站| 久久精品国产福利国产琪琪| 久久综合精品国产二区无码| 久久久久国产视频电影| 色欲综合久久躁天天躁蜜桃| 久久99久久无码毛片一区二区| 国产69精品久久久久久人妻精品| 久久99国产精品久久99| 久久精品国产久精国产一老狼| 青青草国产精品久久| 久久香综合精品久久伊人| 久久久黄片| 美女写真久久影院| 日日躁夜夜躁狠狠久久AV| 中文字幕无码久久人妻| 久久久久久久尹人综合网亚洲 | 国产精品嫩草影院久久| 99精品国产在热久久无毒不卡| 久久久久久精品成人免费图片| 久久无码AV中文出轨人妻| 国产精品狼人久久久久影院 | 伊人久久大香线蕉无码麻豆 | 99久久99久久精品国产片果冻| 久久精品午夜一区二区福利| 2020久久精品亚洲热综合一本| 欧美午夜A∨大片久久| 日日狠狠久久偷偷色综合96蜜桃| 狠狠久久综合伊人不卡| 精品久久久久久无码中文野结衣| 97超级碰碰碰碰久久久久| 一本久久久久久久| 久久噜噜久久久精品66| 亚洲精品久久久www|