全球彩票平台_全球彩票注册平台|官网下载地址

热门关键词: 全球彩票平台,全球彩票注册平台,全球彩官网下载地址

全球彩票注册平台Muduo网络编程示例之四,用户自

Environment::Environment(unsigned int mode)
: _env(NULL)
, _err(NULL)
{
    makeEnvironment(mode);   
}

We could define a Boolean as NUMBER(1); however, in Oracle's internal number format, 0 takes 1 byte and 1 takes 2 bytes after the length byte (so it's more efficient to store it as CHAR). Even though the character is defined as CHAR, SQL can convert and verify against actual numbers.

客商自定义结构数据与VA智跑IANT调换

Telnet 测试
在一个命令行窗口运转

运行:
# g -o test1 test.cpp
# ./test1

std::ostream& operator << (std::ostream& os, const ocipp::Exception& e);

#include <string>
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;

  1. ///////////////////////////////////////////////////////////////////////   
  2. // struct2variant.cpp   
  3. // cheungmine@gmail.com   
  4. // 2010-6   
  5. // 上边包车型大巴前后相继演示了什么样在客商自定义的构造和VAEscortIANT类型之间转移   
  6. // 保留全数义务   
  7. //   
  8. #include "stdafx.h"   
  9. #include "rpc/rpcapi.h"   
  10. #include <assert.h>   
  11. #ifdef _DEBUG   
  12. #  pragma comment(lib, "rpc/rpclib/debug/rpclib.lib")   
  13. #else   
  14. #  pragma comment(lib, "rpc/rpclib/release/rpclib.lib")   
  15. #endif   
  16. // 自定义结构标志   
  17. #define MY_STRUCT_ID  101   // 标记结构的轻便数字   
  18. typedef struct _PointF  
  19. {  
  20.     double x;  
  21.     double y;  
  22. }PointF;  
  23. // 自定义结构   
  24. typedef struct _MyStruct  
  25. {  
  26.     CHAR      id[32];  
  27.     CHAR      server[130];  
  28.     CHAR      instance[10];  
  29.     CHAR      userid[32];  
  30.     BOOL      isdraw;  
  31.     ULONG     token;  
  32.     LONG      timeout;  
  33.     LONG      keepalive;  
  34.     LONG      reserved;  
  35.     BOOL      status;  
  36.     LONG      capacity;  
  37.     LONG volatile counter;  
  38.     // 表达什么保存变长数组   
  39.     SHORT     numPts;  
  40.     PointF   *ptArray;    
  41. }MyStruct;  
  42. void PrintfMyStruct(const char *desc, MyStruct *data)  
  43. {  
  44.     printf("==========%s==========/n", desc);  
  45.     printf("id=%s/n", data->id);  
  46.     printf("server=%s/n", data->server);  
  47.     printf("instance=%s/n", data->instance);  
  48.     printf("userid=%s/n", data->userid);  
  49.     printf("isdraw=%d/n", data->isdraw);  
  50.     printf("token=%d/n", data->token);  
  51.     printf("timeout=%d/n", data->timeout);  
  52.     printf("keepalive=%d/n", data->keepalive);  
  53.     printf("reserved=%d/n", data->reserved);  
  54.     printf("status=%d/n", data->status);  
  55.     printf("capacity=%d/n", data->capacity);  
  56.     printf("counter=%d/n", data->counter);  
  57.     printf("numPts=%d/n", data->numPts);  
  58.     for(int i=0; i<data->numPts; i )  
  59.         printf("ptArray[%d]= (x=%.3lf,     y=%.3lf)/n", i, data->ptArray[i].x, data->ptArray[i].y);  
  60. }  
  61. static HRESULT CreateStreamFromBytes(BYTE *inBytes, DWORD cbSize, IStream **ppStm)  
  62. {  
  63.     HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, 0);  
  64.     ATLASSERT(hGlobal);  
  65.     if (!hGlobal)  
  66.         return E_OUTOFMEMORY;  
  67.       
  68.     CComPtr<IStream> spStm;  
  69.     HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &spStm);  
  70.     ATLASSERT(hr == S_OK);  
  71.     if (hr != S_OK || spStm == 0){  
  72.         GlobalFree(hGlobal);  
  73.         return hr;  
  74.     }  
  75.       
  76.     ULONG  ulWritten = 0;  
  77.     hr = spStm->Write(inBytes, cbSize, &ulWritten);  
  78.     if (hr != S_OK || ulWritten != cbSize)  
  79.         return E_FAIL;  
  80.     return spStm.CopyTo(ppStm);  
  81. }  
  82. ////////////////////////////////////////////////////////////////////   
  83. // 列集自定义数据到VA奥迪Q3IANT   
  84. //   
  85. static void MarshallMyStruct(MyStruct *inData, VARIANT *outVar)  
  86. {  
  87.     assert(inData && outVar);  
  88.     rpc_invoke_descriptor  inv  = {0};  
  89.     rpc_invoke_init(&inv, MY_STRUCT_ID, 14);    // 14个参数   
  90.     // 上边每一个组织成员参数都急需按顺序绑定   
  91.     rpc_invoke_bind_param(&inv,   
  92.                 0,                    /* 结构成员参数索引0-based */  
  93.                 RPCT_STRING,          /* 指明字符串数组类型 */  
  94.                 (void*)inData->id,     /* 指向实际数据的指针 */  
  95.                 strlen(inData->id) 1, /* 只需求保留有效的数据 */  
  96.                 0                     /*0 代表大家不持有id的全体权(不担当释放内部存储器) */  
  97.             );  
  98.     rpc_invoke_bind_param(&inv,   
  99.                 1,  
  100.                 RPCT_STRING,  
  101.                 (void*)inData->server,  
  102.                 strlen(inData->server) 1,  
  103.                 0  
  104.             );  
  105.     rpc_invoke_bind_param(&inv,   
  106.                 2,  
  107.                 RPCT_STRING,  
  108.                 (void*)inData->instance,  
  109.                 strlen(inData->instance) 1,  
  110.                 0  
  111.             );  
  112.     rpc_invoke_bind_param(&inv,   
  113.                 3,  
  114.                 RPCT_STRING,  
  115.                 (void*)inData->userid,  
  116.                 strlen(inData->userid) 1,  
  117.                 0  
  118.             );  
  119.     rpc_invoke_bind_param(&inv,   
  120.                 4,  
  121.                 RPCT_BOOL,  
  122.                 (void*) &inData->isdraw,  
  123.                 0,  /* 不是数组, 为0 */  
  124.                 0  
  125.             );  
  126.     rpc_invoke_bind_param(&inv,   
  127.                 5,  
  128.                 RPCT_ULONG,  
  129.                 (void*) &inData->token,  
  130.                 0,  
  131.                 0  
  132.             );  
  133.     rpc_invoke_bind_param(&inv,   
  134.                 6,  
  135.                 RPCT_LONG,  
  136.                 (void*) &inData->timeout,  
  137.                 0,  
  138.                 0  
  139.             );  
  140.     rpc_invoke_bind_param(&inv,   
  141.                 7,  
  142.                 RPCT_LONG,  
  143.                 (void*) &inData->keepalive,  
  144.                 0,  
  145.                 0  
  146.             );  
  147.     rpc_invoke_bind_param(&inv,   
  148.                 8,  
  149.                 RPCT_LONG,  
  150.                 (void*) &inData->reserved,  
  151.                 0,  
  152.                 0  
  153.             );  
  154.     rpc_invoke_bind_param(&inv,   
  155.                 9,  
  156.                 RPCT_BOOL,  
  157.                 (void*) &inData->status,  
  158.                 0,  
  159.                 0  
  160.             );  
  161.     rpc_invoke_bind_param(&inv,   
  162.                 10,  
  163.                 RPCT_LONG,  
  164.                 (void*) &inData->capacity,  
  165.                 0,  
  166.                 0  
  167.             );  
  168.     rpc_invoke_bind_param(&inv,   
  169.                 11,  
  170.                 RPCT_LONG,  
  171.                 (void*) &inData->counter,  
  172. 全球彩票注册平台Muduo网络编程示例之四,用户自定义结构数据与VARIANT转换。                0,  
  173.                 0  
  174.             );  
  175.     rpc_invoke_bind_param(&inv,   
  176.                 12,  
  177.                 RPCT_SHORT,  
  178.                 (void*) &inData->numPts,  
  179.                 0,  
  180.                 0  
  181.             );  
  182.     rpc_invoke_bind_param(&inv,   
  183.                 13,  
  184.                 RPCT_DOUBLE,    /* 轻易结构的积极分子类型 */  
  185.                 (void*) inData->ptArray, /* 内部存款和储蓄器结构=[x1,y1,x2,y2,...,xn,yn], 千万不可写成:(void*) &inData->ptArray */  
  186.                 inData->numPts * (sizeof(PointF)/sizeof(double)), /* double类型成员的多少=点数x2 */  
  187.                 0  
  188.             );  
  189.     /* 总括调用音信的字节总的数量 */  
  190.     dword_t cbOut = rpc_invoke_get_size(&inv);  
  191.     char *outBuf = (char*) malloc(cbOut);  
  192.       
  193.     /* 列集全数数量到totalBuf中 */  
  194.     rpc_invoke_marshal(&inv, outBuf, cbOut);  
  195.     //////////////////////////////////////////////////////////   
  196.     // 到此,大家早已在outBuf中保存了结构的一体多少,    
  197.     // 下边把多少调换到IStream进而转变到VAKoleosIANT   
  198.     CComPtr<IStream> spStm;  
  199.     CreateStreamFromBytes((BYTE*)outBuf, cbOut, &spStm);  
  200.     VariantInit(outVar);  
  201.     outVar->vt = VT_UNKNOWN;  
  202.     outVar->punkVal = (IUnknown*) spStm.Detach();  
  203.     free(outBuf);  
  204.     rpc_invoke_clear_all(&inv);  
  205. }  
  206. ////////////////////////////////////////////////////////////////////   
  207. // 散集VATiggoIANT到自定义数据   
  208. //   
  209. static void UnmarshallMyStruct(VARIANT *inVar, MyStruct *outData)  
  210. {  
  211.     assert(inVar && outData);  
  212.     assert(inVar->vt==VT_UNKNOWN && inVar->punkVal);  
  213.     HGLOBAL  hGlobal = 0;  
  214.     HRESULT hr = GetHGlobalFromStream((IStream*)inVar->punkVal, &hGlobal);  
  215.     assert(hr==S_OK);  
  216.     size_t  cbData = GlobalSize(hGlobal);  
  217.     char   *pbData = (char*) GlobalLock(hGlobal);  
  218.     char   *rpcHdr = pbData;  
  219.     assert(cbData >= RPC_INVOKE_HEADER_SIZE);  
  220.     assert(rpcHdr[0]=='R' && rpcHdr[1]=='C');  
  221.     rpc_invoke_descriptor  inv={0};  
  222.     rpc_invoke_init(&inv, 0, 0);  
  223.     inv.encPkg = rpcHdr[2];  
  224.     inv.encHdr = rpcHdr[3];  
  225.     assert (inv.encHdr == 0);  
  226.     inv.ordinal = word_ntoh(*((word_t*)(rpcHdr 20)));               // 方法序号: MY_STRUCT_ID   
  227.     assert(inv.ordinal == MY_STRUCT_ID);  
  228.     inv.invToken = dword_ntoh(*((dword_t*)(rpcHdr 4)));             // 客商标志    
  229.     inv.totalBytes = dword_ntoh(*((dword_t*)(rpcHdr 8)));           // 总音讯字节数(恐怕是削减的)   
  230.     inv.bitsFlag = word_ntoh(*((word_t*)(rpcHdr 12)));              // 标志      
  231.     inv.bigEndian = GET_BIT(inv.bitsFlag, RPC_BIGENDIAN_BIT);       // 客商方列集的字节次序   
  232.     inv.reserved = word_ntoh(*((word_t*)(rpcHdr 14)));              // 保留值   
  233.     inv.result = dword_ntoh(*((dword_t*)(rpcHdr 16)));              // 返回值   
  234.     inv.num_params = word_ntoh(*((word_t*)(rpcHdr 22)));            // 参数数目   
  235.     rpc_invoke_error  err={0};  
  236.     rpc_invoke_unmarshal(&inv, rpcHdr, inv.totalBytes, &inv.params_list, &inv.num_params, &err);  
  237.           
  238.     GlobalUnlock(hGlobal);  
  239.     strncpy_s(outData->id, sizeof(outData->id), (char*) inv.params_list[0].param_bytes, sizeof(outData->id)-1);  
  240.     strncpy_s(outData->server, sizeof(outData->server), (char*) inv.params_list[1].param_bytes, sizeof(outData->server)-1);  
  241.     strncpy_s(outData->instance, sizeof(outData->instance), (char*) inv.params_list[2].param_bytes, sizeof(outData->instance)-1);  
  242.     strncpy_s(outData->userid, sizeof(outData->userid), (char*) inv.params_list[3].param_bytes, sizeof(outData->userid)-1);  
  243.     outData->isdraw = PARAMVALUE(inv.params_list, 4, BOOL);  
  244.     outData->token = PARAMVALUE(inv.params_list, 5, ULONG);  
  245.     outData->timeout = PARAMVALUE(inv.params_list, 6, LONG);  
  246.     outData->keepalive = PARAMVALUE(inv.params_list, 7, LONG);  
  247. 全球彩票注册平台Muduo网络编程示例之四,用户自定义结构数据与VARIANT转换。    outData->reserved = PARAMVALUE(inv.params_list, 8, LONG);  
  248.     outData->status = PARAMVALUE(inv.params_list, 9, BOOL);  
  249.     outData->capacity = PARAMVALUE(inv.params_list, 10, LONG);  
  250.     outData->counter = PARAMVALUE(inv.params_list, 11, LONG);  
  251.     outData->numPts = PARAMVALUE(inv.params_list, 12, SHORT);  
  252.     // 为出口分配 ptArray   
  253.     outData->ptArray = (PointF*) malloc(sizeof(PointF)*outData->numPts);  
  254.     memcpy(outData->ptArray, inv.params_list[13].param_bytes, sizeof(PointF)*outData->numPts);  
  255.     rpc_invoke_clear_all(&inv);  
  256. }  
  257. int main(int argc, CHAR* argv[])  
  258. {  
  259.     MyStruct     data, data2;  
  260.     CComVariant  var;   // 这几个var 能够储存在任何必要使用到的地方   
  261.     // 起初化结构data   
  262.     strcpy_s(data.id, sizeof(data.id), "13890");  
  263.     strcpy_s(data.server, sizeof(data.server), "localhost");  
  264.     strcpy_s(data.instance, sizeof(data.instance), "port:6755");  
  265.     strcpy_s(data.userid, sizeof(data.userid), "cheungmine");  
  266.     data.isdraw = 1;  
  267.     data.token = 54321;  
  268.     data.timeout = 3000;  
  269.     data.keepalive = 6500;  
  270.     data.reserved=0;  
  271.     data.status = 0;  
  272.     data.capacity = 4096;  
  273.     data.counter = 99;  
  274.     data.numPts = 16;  
  275.     data.ptArray = (PointF*) malloc(data.numPts*sizeof(PointF));  
  276.     for(int i=0; i<data.numPts; i ){  
  277.         data.ptArray[i].x = 100 i;  
  278.         data.ptArray[i].y = 200 i;  
  279.     }  
  280.     PrintfMyStruct("input MyStruct", &data);  
  281.       
  282.     // 顾客的布局转变为VASportageIANT: data=>var   
  283.     MarshallMyStruct(&data, &var);  
  284.     free(data.ptArray);  
  285.     // ...使用var   
  286.     // VASportageIANT转为客商的组织: var=>data   
  287.     UnmarshallMyStruct(&var, &data2);  
  288.     PrintfMyStruct("output MyStruct", &data2);  
  289.     free(data2.ptArray);  
  290. }  

   1: #include    2: #include    3:     4: using namespace muduo;   5: using namespace muduo::net;   6:     7: int main()   8: {   9:   EventLoop loop;  10:   TcpServer server(&loop, InetAddress(1079), "Finger");  11:   server.start();  12:   loop.loop();  13: }
3 主动断开连接 接受新连接之后主动断开。finger03.cc

              cout<<"deptno="<<deptno<<",dname="<<dname<<endl;

    int ret = OCIHandleAlloc((const void*)_env, (void**)&(conn->_srv), OCI_HTYPE_SERVER, 0, NULL);
    if((ret != OCI_SUCCESS && ret != OCI_SUCCESS_WITH_INFO) || conn->_srv == NULL)
    {
        throw Exception(ret, "create Server failed.");
    }

create table tbool (bool char check (bool in ('N','Y'));
insert into tbool values ('N');
insert into tbool values ('Y');

 

   1: #include    2:     3: using namespace muduo;   4: using namespace muduo::net;   5:     6: int main()   7: {   8:   EventLoop loop;   9:   loop.loop();  10: }
2 接受新连接 在 1079 端口侦听新连接,接受连接之后怎样都不做,程序空等。muduo 会自动屏弃收到的数目。finger02.cc

    string strsql("select deptno,dname from dept");

Connection* Environment::makeConnection(const std::string &user, const std::string &passwd, const std::string &server)
{
    Connection *conn = new Connection(this);

public class bool
{
    public static void main(String[] args) throws SQLException
    {
        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        }
        catch (ClassNotFoundException e)
        {
            System.out.println("error: driver not in CLASSPATH");
            return;
        }
        Connection conn = DriverManager.getConnection(
            "jdbc:oracle:oci8:@","scott","tiger");
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery("select bool from tbool");
        Boolean bool;
        while (rset.next())
        {
            if (rset.getBoolean(1))
                System.out.println("bool is true");
            else System.out.println("bool is false");
        }
        rset.close();
        stmt.close();
        conn.close();
    }
}

 

$ telnet localhost 1079
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
muduo
No such user
Connection closed by foreign host.

(2)测试C 程序test.cpp
#include <iostream>    
using namespace std;                      
int main()                                  
{                                            
    cout << "Come up and C me some time.";  
    cout << endl;                            
    cout << "You won't regret it!" << endl;  
    return 10;                                
}

    void show(std::ostream& os) const;
protected:
    void getError(int code);
    void getError(int code, OCIError *err);
protected:
    int _code;
    std::string _msg;
};

Also, in OCI, OCCI, and PRO/C, if the selected value is requested as an integer (SQLT_INT or OCCIINT), it will automatically convert into binary 0 or 1 by the client-side libraries, which can be used as native Boolean values.

 

再试壹次

(1)配置ld.so.conf文件,填入如下内容:
# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/lib/oracle/11.2/client64/lib

    ret = OCIStmtPrepare(stmt->_stmt, _env->getError(), (const OraText*)sql.c_str(), sql.size(), OCI_NTV_SYNTAX, OCI_DEFAULT);
    if(ret != OCI_SUCCESS)
    {
        throw Exception(ret, _env->getError(), "prepare Stmt failed.");
    }

create table tbool (bool char check (bool in (0,1));
insert into tbool values(0);
insert into tbool values(1);

其一进程是闻名海外的,可是,真正把结构列集成字节数组,固然不想接纳一些标称的连串化的法子,而全部和睦写,的确要费一番武术。不是

拒绝连接 什么都不做,程序空等。finger01.cc 1: #include 2: 3: using namespace muduo; 4: using namespace muduo::net; 5: 6: int main() 7: { 8: EventLoop loop; 9: loop...

(2)配置/etc/hosts文件(此处填入Linux系统主机的IP地址和主机名称),填入如下内容:
# vi /etc/hosts
127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4
::1        localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.48.128 MyRHEL

class Statement;

When creating a Boolean data column, you should be careful to make sure that the column is properly "nullable." If a column with two possible values isn't constrained with NOT NULL, then you're allowing three possible values: true, false, and unknown. This is often not what is intended and host languages environments must deal with the possibility that NULL is returned. Either 2-value or 3-value may be acceptable in certain circumstances. This SQL restricts a BOOLEAN value to 2-values only:

[cpp] view plaincopyprint?

   1: void onConnection(const TcpConnectionPtr& conn)   2: {   3:   if (conn->connected())   4:   {   5:     conn->shutdown();   6:   }   7: }   8:     9: int main()  10: {  11:   EventLoop loop;  12:   TcpServer server(&loop, InetAddress(1079), "Finger");  13:   server.setConnectionCallback(onConnection);  14:   server.start();  15:   loop.loop();  16: }
4 读取客户名,然后断开连接 若果读到一行以 结尾的音信,就断开连接。finger04.cc

              cout <<"conn success"<< endl;

int Statement::bindString(unsigned int pos, const std::string &val)
{
    OCIBind* bd = NULL;
    int ret = OCIBindByPos(_stmt, &bd, _conn->getEnvironment()->getError(), pos, (void*)val.c_str(), val.size() 1/**//* very dangerous */, SQLT_STR, NULL, NULL, NULL, 0, NULL, OCI_DEFAULT);
    if(ret != OCI_SUCCESS)
    {
        throw Exception(ret, _conn->getEnvironment()->getError(), "bind String failed.");
    }

create or replace package body bool
as
    function false return bool
    is
    begin
        return 0;
    end false;
    --
    function true return bool
    is
    begin
        return 1;
    end true;
    --
    function val(b bool) return varchar2
    is
    begin
        if b = true then
            return 'true';
        end if;
        return 'false';
    end val;
end bool;
/
show error

非常少说废话,全体内容见下边包车型客车代码,作者还有恐怕会上传整个工程。

   1: typedef std::map UserMap;   2: UserMap users;   3:     4: string getUser(const string& user)   5: {   6:   string result = "No such user";   7:   UserMap::iterator it = users.find(user);   8:   if (it != users.end())   9:   {  10:     result = it->second;  11:   }  12:   return result;  13: }  14:    15: void onMessage(const TcpConnectionPtr& conn,  16:                Buffer* buf,  17:                Timestamp receiveTime)  18: {  19:   const char* crlf = buf->findCRLF();  20:   if (crlf)  21:   {  22:     string user(buf->peek(), crlf);  23:     conn->send(getUser(user) " ");  24:     buf->retrieveUntil(crlf 2);  25:     conn->shutdown();  26:   }  27: }  28:    29: int main()  30: {  31:   EventLoop loop;  32:   TcpServer server(&loop, InetAddress(1079), "Finger");  33:   server.setMessageCallback(onMessage);  34:   server.start();  35:   loop.loop();  36: }
7. 往 UserMap 里增加二个客商 与前方大致统统一致,只多了第 31 行。finger07.cc

              int deptno = rset->getInt(1);

}

insert into tbool values(bool.false);
insert into tbool values(bool.true);

[cpp] view plaincopyprint?

安然难题同上。

gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

int Statement::execute()
{
    unsigned short type = 0;
    int ret = OCIAttrGet((const void*)_stmt, OCI_HTYPE_STMT, (void*)&type, 0, OCI_ATTR_STMT_TYPE, _conn->getEnvironment()->getError());
    if(ret != OCI_SUCCESS)
    {
        throw Exception(ret, _conn->getEnvironment()->getError(), "get Stmt type failed.");
    }

int main(int argc,char* argv[])
{
    bool b;
    Environment* env = Environment::createEnvironment();
    try
    {
        Connection* conn = env->createConnection("scott","tiger");
        Statement* stmt = conn->createStatement("select bool from tbool");
        ResultSet* rset = stmt->executeQuery();
        rset->setDataBuffer(1,&b,OCCIINT,sizeof(bool));
        while (rset->next())
        {
            if (b) cout << "bool was true" << endl;
            else cout << "bool was false" << endl;
        }
        stmt->closeResultSet(rset);
        conn->terminateStatement(stmt);
        env->terminateConnection(conn);
    }
    catch (SQLException e)
    {
        cout << e.what() << endl;
    }
    Environment::terminateEnvironment(env);
    return 0;
}

  1. /** 
  2.  * rpcapi.h -cheungmine@gmail.com 
  3.  * all rights reserved 2009 
  4.  */  
  5. #ifndef _RPCAPI_H__   
  6. #define _RPCAPI_H__   
  7. #include <winsock2.h>   
  8. #pragma comment(lib, "ws2_32.lib")   
  9. #include <process.h>  /* _beginthreadex, _endthread */   
  10. #include "../rc4/unistd.h"   
  11. #include "../rc4/md5.h"   
  12. #include "../rc4/rc4.h"   
  13. #include "rpctype.h"   
  14. #include "rpcerr.h"   
  15. #ifdef __cplusplus   
  16. extern "C" {  
  17. #endif   
  18. static BOOL  _rpc_is_bigendian = (('4321'>>24)=='1');  
  19. #define PARAMVALUE(pl,i,type)     ((type)(*((type*) pl[i].param_bytes)))   
  20. typedef enum  
  21. {  
  22.     RPC_ENCHEADER_BIT  = 0,  
  23.     RPC_ENCPACKAGE_BIT  = 1,  
  24.     RPC_BIGENDIAN_BIT  = 7  
  25. }RPC_BITFLAG_ENUM;  
  26. /** 
  27.  * param descriptor  
  28.  */  
  29. #define RPC_PARAM_HEADER_SIZE  16   
  30. typedef struct _rpc_param_descriptor  
  31. {  
  32.     word_t      param_type;         // 参数类型:变量类型或协会类型   
  33.     word_t      size_type;          // 参数类型尺寸字节   
  34.     size_t      array_size;         // 数组成分数目: 0 不是数组; >0数组   
  35.       
  36.     size_t      param_size;         // 参数数据字节数=参数类型尺寸字节*要素数目   
  37.     void       *param_bytes;        // 指向参数数据的指针的援引, 不复制数据   
  38.     BOOL        is_owner;           // 是或不是具有数据. 假如为TRUE, 须求free(param_bytes)   
  39. }rpc_param_descriptor;  
  40. /** 
  41.  * invoke descriptor  
  42.  */  
  43. #define RPC_INVOKE_HEADER_SIZE  24      /* 不得以退换 */   
  44. typedef struct _rpc_invoke_descriptor  
  45. {  
  46.     /* 24字节头   内容 
  47.      *  ['RCmn'(4)|客户标记(4)|总新闻字节(4)|标记(2)| 保留(2)|原始字节数(4)|方法序号(2)|参数数目(2)] 
  48.      */  
  49.     dword_t                totalBytes;  // 总消息字节4   
  50.     word_t                 bitsFlag;    // 标志位2: [7=BigEndian]   
  51.     word_t                 reserved;    // 保留2   
  52.     dword_t                result;      // 返回值   
  53.     // 内部值, 调用时,要求列集在bitsFlag中   
  54.     dword_t                invToken;  
  55.     byte                   bigEndian;  
  56.     byte                   encHdr;  
  57.     byte                   encPkg;  
  58.     // 如若缩减或加密, 从以下职责内容起头      
  59.     ushort                 ordinal;     // 方法序号2       
  60.     ushort                 num_params;  // 参数数目   
  61.     rpc_param_descriptor  *params_list; // 参数列表   
  62.     // 做为输入时, 存放有的时候值   
  63.     //   
  64.     char                  *pbBuf;  
  65.     union{  
  66.         char               bVal;  
  67.         long               lVal;  
  68.         short              sVal;  
  69.         float              fVal;  
  70.         double             dVal;  
  71.         __int64            llVal;  
  72.     };  
  73. }rpc_invoke_descriptor;  
  74. /** 
  75.  * connection descriptor 
  76.  */  
  77. typedef struct _rpc_connection_descriptor  
  78. {  
  79.     BOOL               is_bigendian;    // 字节顺序   
  80.     dword_t            token;           // 调用标识   
  81.     dword_t            timeout;         // 超时   
  82.     byte               enc_hdr;         // 头加密标识   
  83.     byte               enc_pkg;         // 参数包加密标识   
  84.     SOCKET             stream;          // SOCKET 连接   
  85.     char               host[130];       // 主机名或IP地址   
  86.     char               port[6];         // 端口号   
  87.       
  88.     rpc_invoke_error   last_err;        // 近些日子的错误   
  89.     char               buffer[RPC_BUFFSIZE];  // 互联网传输缓冲区   
  90. }rpc_connection_descriptor;  
  91. /*============================================================================= 
  92.                               Private Functions 
  93.                  host byte order and network byte order transform 
  94. =============================================================================*/  
  95. static int SafeStringSize(const char* psz)  
  96. {  
  97.     return (int)(psz? (strlen(psz) 1):0);  
  98. }  
  99. /** 
  100.  * More fast than swap_bytes(...) for handle word and dword type 
  101.  */  
  102. #define swap_word_type(x)  ((WORD)(((((WORD)(x))&0x00ff)<<8)|((((WORD)(x))&0xff00)>>8)))   
  103. #define swap_dword_type(x)  ((DWORD)(((((DWORD)(x))&0xff000000)>>24)|((((DWORD)(x))&0x00ff0000)>>8)|((((DWORD)(x))&0x0000ff00)<<8)|((((DWORD)(x))&0x000000ff)<<24)))   
  104. static void swap_bytes(void *wordP, size_t cbSize /*must be 2, 4, 8 */)  
  105. {  
  106.     size_t   i;  
  107.     byte     t;  
  108.     for(i=0; i<cbSize/2; i ){  
  109.         t = ((byte *) wordP)[i];  
  110.         ((byte *)wordP)[i] = ((byte *) wordP)[cbSize-i-1];  
  111.         ((byte *) wordP)[cbSize-i-1] = t;  
  112.     }  
  113. }  
  114. static dword_t  dword_hton(dword_t host)  
  115. {  
  116.     if (!_rpc_is_bigendian)  
  117.         host = swap_dword_type(host);  
  118.     return  host;  
  119. }  
  120. static dword_t  dword_ntoh(dword_t net)  
  121. {  
  122.     if (!_rpc_is_bigendian)  
  123.         net = swap_dword_type(net);  
  124.     return  net;  
  125. }  
  126. static word_t   word_hton(word_t host)  
  127. {  
  128.     if (!_rpc_is_bigendian)  
  129.         host = swap_word_type(host);  
  130.     return  host;  
  131. }  
  132. static word_t   word_ntoh(word_t net)  
  133. {  
  134.     if (!_rpc_is_bigendian)  
  135.         net = swap_word_type(net);  
  136.     return  net;  
  137. }  
  138. static qword_t  qword_hton(qword_t host)  
  139. {  
  140.     if (!_rpc_is_bigendian)  
  141.         swap_bytes(&host, sizeof(qword_t));  
  142.     return  host;  
  143. }  
  144. static qword_t  qword_ntoh(qword_t net)  
  145. {  
  146.     if (!_rpc_is_bigendian)  
  147.         swap_bytes(&net, sizeof(qword_t));  
  148.     return  net;  
  149. }  
  150. static double   double_hton(double host)  
  151. {  
  152.     if (!_rpc_is_bigendian)  
  153.         swap_bytes(&host, sizeof(qword_t));  
  154.     return  host;  
  155. }  
  156. static double   double_ntoh(double net)  
  157. {  
  158.     if (!_rpc_is_bigendian)  
  159.         swap_bytes(&net, sizeof(qword_t));  
  160.     return  net;  
  161. }  
  162. static float    float_hton(float host)  
  163. {  
  164.     if (!_rpc_is_bigendian)  
  165.         swap_bytes(&host, sizeof(dword_t));  
  166.     return  host;  
  167. }  
  168. static float    float_ntoh(float net)  
  169. {  
  170.     if (!_rpc_is_bigendian)  
  171.         swap_bytes(&net, sizeof(dword_t));  
  172.     return  net;  
  173. }  
  174. /*============================================================================= 
  175.                               Private Functions 
  176.                            socket helper functions 
  177. =============================================================================*/  
  178. static int setbufsize(SOCKET s, int rcvlen /*RPC_BUFFSIZE*/, int sndlen /*RPC_BUFFSIZE*/)  
  179. {  
  180.     int rcv, snd;  
  181.     int rcvl = (int) sizeof(int);  
  182.     int sndl = rcvl;  
  183.     if ( getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*)&rcv, &rcvl)==SOCKET_ERROR ||  
  184.          getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char*)&snd, &sndl)==SOCKET_ERROR )  
  185.         return SOCKET_ERROR;  
  186.       
  187.     if(rcv < rcvlen){  
  188.         rcv = rcvlen;  
  189.         rcvl = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*)&rcv, rcvl);  
  190.         assert(rcvl==0);  
  191.     }  
  192.       
  193.     if(snd < sndlen){  
  194.         snd = sndlen;     
  195.         sndl = setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char*)&snd, sndl);  
  196.         assert(sndl==0);  
  197.     }  
  198.     return 0;  
  199. }  
  200. static int sendmsg(SOCKET s, const char* msgbuf, int msglen, int flags)  
  201. {  
  202.     int ret;  
  203.     int offset = 0;  
  204.     int left = msglen;    
  205.     while (left > 0) {  
  206.         ret = send(s, &msgbuf[offset], left, flags);  
  207.         if (ret==SOCKET_ERROR || ret==0)  
  208.             return ret;       
  209.         left -= ret;  
  210.         offset  = ret;  
  211.     }  
  212.     assert(offset==msglen);  
  213.     return offset;  
  214. }  
  215. static int recvmsg(SOCKET s, char* msgbuf, int buflen, int flags)  
  216. {  
  217.     int     ret;  
  218.     int     offset = 0;  
  219.     int     left = buflen;    
  220.     while (left > 0){  
  221.         ret = recv(s, &msgbuf[offset], left, flags);  
  222.         if (ret==SOCKET_ERROR || ret==0)  
  223.             return ret;  
  224.         offset  = ret;  
  225.         left -= ret;  
  226.     }  
  227.     assert(offset==buflen);  
  228.     return offset;  
  229. }  
  230. static BOOL sendbulk(SOCKET s, const char* data, int dataSize, int flags, int maxmsg)  
  231. {  
  232.     int send, ret;  
  233.     int offset = 0;  
  234.     int left = dataSize;  
  235.     while (left > 0) {  
  236.         send = left>maxmsg? maxmsg:left;  
  237.         ret = sendmsg(s, &data[offset], send, flags);  
  238.         if (ret != send)  
  239.             return FALSE;  
  240.         offset  = ret;  
  241.         left -= ret;  
  242.     }  
  243.     return TRUE;  
  244. }  
  245. static BOOL recvbulk(SOCKET s, char* buf, int recvlen, int flags, int maxmsg)  
  246. {  
  247.     int  recv, ret;  
  248.     int  offset = 0;  
  249.     int  left = recvlen;  
  250.     while (left > 0){  
  251.         recv = left>maxmsg? maxmsg:left;  
  252.         ret = recvmsg(s, &buf[offset], recv, flags);  
  253.         if (ret != recv)  
  254.             return FALSE;  
  255.         offset  = ret;  
  256.         left -= ret;  
  257.     }  
  258.     return TRUE;  
  259. }  
  260. static LPCSTR errmsg(DWORD dwCode, LPSTR lpszMsgBuf, DWORD dwMsgBufBytes)  
  261. {  
  262.     FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,  
  263.             NULL, dwCode, 0, /* Default language */  
  264.             lpszMsgBuf,  
  265.             dwMsgBufBytes,  
  266.             NULL);  
  267.     return lpszMsgBuf;  
  268. }  
  269. static void rpc_error_clear(rpc_invoke_error *err)  
  270. {  
  271.     err->err_type = RPC_NO_ERROR;  
  272.     err->err_code = 0;  
  273.     *err->err_source = 0;  
  274.     *err->err_detail = 0;  
  275. }  
  276. // [RESM(4)|总音讯字节(4)|err_type(2)|err_code(2)|err_source_size(2)|err_source_string|err_detail_size(2)|err_detail_string]   
  277. static BOOL rpc_error_short_msg(SOCKET s, char *buf, int size, rpc_invoke_error *err)  
  278. {  
  279.     int pos = 0;  
  280.     word_t w;  
  281.     ushort err_source_size = (ushort)strlen(err->err_source) 1;  
  282.     ushort err_detail_size = (ushort)strlen(err->err_detail) 1;  
  283.     ulong  msglen = 4 4 2 2 2 err_source_size 2 err_detail_size;  
  284.     *buf = 0;  
  285.     assert((ulong)size>=msglen);  
  286.     buf[pos ] = 'R';  
  287.     buf[pos ] = 'E';  
  288.     buf[pos ] = 'S';  
  289.     buf[pos ] = 'M';  
  290.       
  291.     msglen = dword_hton(msglen);  
  292.     memcpy(buf pos, &msglen, 4);  
  293.     pos  = 4;  
  294.     w = word_hton((word_t)err->err_type);  
  295.     memcpy(buf pos, &w, 2);  
  296.     pos  = 2;  
  297.     w = word_hton((word_t)err->err_code);  
  298.     memcpy(buf pos, &w, 2);  
  299.     pos  = 2;  
  300.     w = word_hton((word_t)err_source_size);  
  301.     memcpy(buf pos, &w, 2);  
  302.     pos  = 2;     
  303.     memcpy(buf pos, err->err_source, err_source_size);  
  304.     pos  = err_source_size;  
  305.     w = word_hton((word_t)err_detail_size);  
  306.     memcpy(buf pos, &w, 2);  
  307.     pos  = 2;  
  308.     memcpy(buf pos, err->err_detail, err_detail_size);  
  309.     pos  = err_detail_size;  
  310.     assert((ulong)pos == dword_ntoh(msglen));  
  311.     if (pos == (ulong)sendmsg(s, buf, pos, 0))  
  312.         return TRUE;  
  313.     err->err_type = RPC_SOCKET_ERROR;  
  314.     err->err_code = WSAGetLastError();  
  315.     *err->err_source = 0;  
  316.     errmsg(err->err_code, err->err_detail, RPC_ERROR_STRING_LEN);  
  317.       
  318.     return FALSE;  
  319. }  
  320. static void debug_out(const char *debug_file, const char *fmt, ...)  
  321. {  
  322. #ifdef _DEBUG   
  323.     FILE *fp = 0;  
  324.     va_list ap;  
  325.       
  326.     fopen_s(&fp, debug_file, "a ");  
  327.     assert(fp);  
  328.       
  329.     va_start(ap, fmt);  
  330.     vfprintf(fp, fmt, ap);  
  331.     va_end(ap);  
  332.     fclose(fp);  
  333. #endif   
  334. }  
  335. /*============================================================================ 
  336.                        RPC PUBLIC FUNCTIONS 
  337.  ============================================================================*/  
  338. /** 
  339.  * rpc_throw_error 
  340.  */  
  341. RPCRESULT rpc_throw_error(RPC_ERROR_TYPE err_type, LONG err_code, const char* err_source, rpc_invoke_error *err);  
  342. /** 
  343.  * rpc_invoke_free 
  344.  *   创立RPC调用描述符 
  345.  */  
  346. rpc_invoke_descriptor* rpc_invoke_create(rpc_invoke_descriptor **inv, ushort ordinal, ushort num_params);  
  347. /** 
  348.  * rpc_invoke_init 
  349.  *   起头化RPC调用描述符 
  350.  */  
  351. rpc_invoke_descriptor *  
  352. rpc_invoke_init(rpc_invoke_descriptor *inv, ushort ordinal, ushort num_params);  
  353. /** 
  354.  * rpc_invoke_clear_all 
  355.  *   清除RPC调用描述符, 此后RPC调用描述符能够重复绑定变量 
  356.  */  
  357. void rpc_invoke_clear_all(rpc_invoke_descriptor *inv);  
  358. /** 
  359.  * rpc_invoke_free 
  360.  *   删除RPC调用描述符, 此后RPC调用描述符将不可用 
  361.  */  
  362. void rpc_invoke_free(rpc_invoke_descriptor *inv);  
  363. /** 
  364.  * rpc_invoke_set_param 
  365.  *   设置钦命的参数, 重回参数指针 
  366.  */  
  367. rpc_param_descriptor* rpc_invoke_set_param(rpc_invoke_descriptor *inv, ushort id, word_t type);  
  368. /** 
  369.  * rpc_param_clear 
  370.  *   清除参数内容 
  371.  */  
  372. void rpc_param_clear(rpc_param_descriptor *param);  
  373. /** 
  374.  * rpc_param_free_list 
  375.  *   清除参数列表内容 
  376.  */  
  377. void rpc_param_free_list(rpc_param_descriptor *param_list, word_t num_params);  
  378. /** 
  379.  * rpc_connection_create 
  380.  *   创建RPC连接 
  381.  */  
  382. RPCRESULT rpc_connection_create(rpc_connection_descriptor **conn, const char *host, const char *port, long rcvtimeo, rpc_invoke_error *err);  
  383. /** 
  384.  * rpc_connection_free 
  385.  *   清除RPC连接 
  386.  */  
  387. void rpc_connection_free(rpc_connection_descriptor *conn);  
  388. /** 
  389.  * rpc_connection_set 
  390.  *   设置RPC连接的属性 
  391.  */  
  392. void rpc_connection_set(rpc_connection_descriptor *conn, dword_t token, dword_t timeout, byte encheader, byte encpackage);  
  393. /** 
  394.  * rpc_connection_free 
  395.  *   设置输入的参数, 再次来到参数指针 
  396.  */  
  397. rpc_param_descriptor* rpc_invoke_bind_param(rpc_invoke_descriptor *inv, ushort id, word_t type, void *vaddr, size_t array_size, BOOL is_owner);  
  398. /** 
  399.  * rpc_connection_free 
  400.  *   总计参数字节总的数量 
  401.  */  
  402. dword_t rpc_param_get_size(rpc_param_descriptor *param);  
  403. /** 
  404.  * rpc_connection_free 
  405.  *   总结调用新闻的字节总的数量 
  406.  */  
  407. dword_t rpc_invoke_get_size(rpc_invoke_descriptor *inv);  
  408. /** 
  409.  * rpc_invoke_marshal 
  410.  *   列集全部数据到totalBuf中 
  411.  */  
  412. int rpc_invoke_marshal(rpc_invoke_descriptor *inv, char *totalBuf, int totalSize);  
  413. /** 
  414.  * rpc_invokehdr_unmarshal 
  415.  *   散集调用头 
  416.  */  
  417. RPCRESULT rpc_invokehdr_unmarshal(SOCKET sClient, dword_t dwToken, char *rpcHdr, int hdrSize, rpc_invoke_descriptor *inv, rpc_invoke_error *err);  
  418. /** 
  419.  * rpc_invoke_unmarshal 
  420.  *   散集数据到参数中 
  421.  */  
  422. RPCRESULT rpc_invoke_unmarshal(rpc_invoke_descriptor *inv,   
  423.                                char                  *totalBuf,   
  424.                                size_t                 totalSize,  
  425.                                rpc_param_descriptor **out_params,  
  426.                                word_t                *num_params,  
  427.                                rpc_invoke_error      *err);  
  428. /** 
  429.  * rpc_param_get_short 
  430.  *   获得短整数参数值 
  431.  */  
  432. void rpc_param_get_short (rpc_param_descriptor *param, SHORT *val);  
  433. /** 
  434.  * rpc_param_get_ushort 
  435.  *   取得短整数参数值 
  436.  */  
  437. void rpc_param_get_ushort (rpc_param_descriptor *param, USHORT *val);  
  438. /** 
  439.  * rpc_param_get_long 
  440.  *   获得整数参数值 
  441.  */  
  442. void rpc_param_get_long (rpc_param_descriptor *param, LONG *val);  
  443. /** 
  444.  * rpc_param_get_ulong 
  445.  *   取得无符号整数参数值 
  446.  */  
  447. void rpc_param_get_ulong (rpc_param_descriptor *param, ULONG *val);  
  448. /** 
  449.  * rpc_param_get_int 
  450.  *   获得整数参数值 
  451.  */  
  452. void rpc_param_get_int (rpc_param_descriptor *param, INT *val);  
  453. /** 
  454.  * rpc_param_get_double 
  455.  *   猎取双精度参数值 
  456.  */  
  457. void rpc_param_get_double (rpc_param_descriptor *param, double *val);  
  458. /** 
  459.  * rpc_invoke_send 
  460.  *   发送数据 
  461.  */  
  462. RPCRESULT rpc_invoke_send(rpc_connection_descriptor *conn, rpc_invoke_descriptor *inv, rpc_invoke_error *err);  
  463. /** 
  464.  * rpc_invoke_recv 
  465.  *   接收数据 
  466.  */  
  467. RPCRESULT rpc_invoke_recv(rpc_connection_descriptor *conn, rpc_invoke_descriptor *outv, rpc_invoke_error *err);  
  468. /** 
  469.  * rpc_connection_free 
  470.  *   执行RPC调用 
  471.  */  
  472. RPCRESULT rpc_invoke_execute(rpc_connection_descriptor *conn,   
  473.                              rpc_invoke_descriptor     *inv,   
  474.                              rpc_invoke_descriptor     *outv,   
  475.                              rpc_invoke_error          *err);  
  476. #ifdef __cplusplus   
  477. }  
  478. #endif   
  479. #endif /* _RPCAPI_H__ */  

 1 拒绝连接 怎样都不做,程序空等。finger01.cc

(2)编写翻译运维:
[root@MyRHEL test]# g -o connclient  connclient.cpp -L /usr/lib/oracle/11.2/client64/lib  -I /usr/include/oracle/11.2/client64/  -locci  -lclntsh  /usr/lib64/libstdc .so.6
[root@MyRHEL test]# ./connclient
conn success
deptno=10,dname=ACCOUNTING
deptno=20,dname=RESEARCH
deptno=30,dname=SALES
deptno=40,dname=OPERATIONS

#include <string>
#include <iostream>
#include <vector>

create table tbool (bool char not null check (bool in (0,1));

rpcapi.c如下:

$ telnet localhost 1079
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
schen
Happy and well
Connection closed by foreign host.

 

class Environment
{
public:
    Environment(unsigned int mode = OCI_DEFAULT);
    virtual ~Environment();

By using setDataBuffer with a C bool value, the correct integer value gets bound to a C bool. Unfortunately, there's no getBoolean in OCCI. Therefore, it may be more portable to use an int or char, or use rset->getInt(1) instead of binding. (Note: In my tests, there is apparently a bug in OCCI where using getInt(1) on a CHAR column failed unless I used to_number(bool) or bool 0.)

 

$ ./bin/twisted_finger07

#include<occi.h>

#include "ocipp.h"

However, Oracle SQL still requires a condition operator, so there's no way to get around testing for the actual value being 1 or 0, although you can hide these values in a standardization package. For instance, see how I can reuse/expose the keywords true and false through a PL/SQL package:

/** * rpcapi.h -cheungmine@gmail.com * all rights reserved 2009 */ #ifndef _RPCAPI_H__ #define _RPCAPI_H__ #include <winsock2.h> #pragma comment(lib, "ws2_32.lib") #include <process.h> /* _beginthreadex, _endthread */ #include "../rc4/unistd.h" #include "../rc4/md5.h" #include "../rc4/rc4.h" #include "rpctype.h" #include "rpcerr.h" #ifdef __cplusplus extern "C" { #endif static BOOL _rpc_is_bigendian = (('4321'>>24)=='1'); #define PARAMVALUE(pl,i,type) ((type)(*((type*) pl[i].param_bytes))) typedef enum { RPC_ENCHEADER_BIT = 0, RPC_ENCPACKAGE_BIT = 1, RPC_BIGENDIAN_BIT = 7 }RPC_BITFLAG_ENUM; /** * param descriptor */ #define RPC_PARAM_HEADER_SIZE 16 typedef struct _rpc_param_descriptor { word_t param_type; // 参数类型:变量类型或协会类型 word_t size_type; // 参数类型尺寸字节 size_t array_size; // 数组成分数目: 0 不是数组; >0数组 size_t param_size; // 参数数据字节数=参数类型尺寸字节*要素数目 void *param_bytes; // 指向参数数据的指针的援用, 不复制数据 BOOL is_owner; // 是还是不是富有数据. 假设为TRUE, 须要free(param_bytes) }rpc_param_descriptor; /** * invoke descriptor */ #define RPC_INVOKE_HEADER_SIZE 24 /* 不可以改变 */ typedef struct _rpc_invoke_descriptor { /* 24字节头 内容 * ['RCmn'(4)|顾客标记(4)|总音讯字节(4)|标记(2)| 保留(2)|原始字节数(4)|方法序号(2)|参数数目(2)] */ dword_t totalBytes; // 总音讯字节4 word_t bitsFlag; // 标志位2: [7=BigEndian] word_t reserved; // 保留2 dword_t result; // 重回值 // 内部值, 调用时,须求列集在bitsFlag中 dword_t invToken; byte bigEndian; byte encHdr; byte encPkg; // 如若缩减或加密, 从以下职责内容早先 ushort ordinal; // 方法序号2 ushort num_params; // 参数数目 rpc_param_descriptor *params_list; // 参数列表 // 做为输入时, 寄放有的时候值 // char *pbBuf; union{ char bVal; long lVal; short sVal; float fVal; double dVal; __int64 llVal; }; }rpc_invoke_descriptor; /** * connection descriptor */ typedef struct _rpc_connection_descriptor { BOOL is_bigendian; // 字节顺序 dword_t token; // 调用标志 dword_t timeout; // 超时 byte enc_hdr; // 头加密标识 byte enc_pkg; // 参数包加密标记 SOCKET stream; // SOCKET 连接 char host[130]; // 主机名或IP地址 char port[6]; // 端口号 rpc_invoke_error last_err; // 近来的荒谬 char buffer[RPC_BUFFSIZE]; // 网络传输缓冲区 }rpc_connection_descriptor; /*============================================================================= Private Functions host byte order and network byte order transform =============================================================================*/ static int SafeStringSize(const char* psz) { return (int)(psz? (strlen(psz) 1):0); } /** * More fast than swap_bytes(...) for handle word and dword type */ #define swap_word_type(x) ((WORD)(((((WORD)(x))&0x00ff)<<8)|((((WORD)(x))&0xff00)>>8))) #define swap_dword_type(x) ((DWORD)(((((DWORD)(x))&0xff000000)>>24)|((((DWORD)(x))&0x00ff0000)>>8)|((((DWORD)(x))&0x0000ff00)<<8)|((((DWORD)(x))&0x000000ff)<<24))) static void swap_bytes(void *wordP, size_t cbSize /*must be 2, 4, 8 */) { size_t i; byte t; for(i=0; i<cbSize/2; i ){ t = ((byte *) wordP)[i]; ((byte *)wordP)[i] = ((byte *) wordP)[cbSize-i-1]; ((byte *) wordP)[cbSize-i-1] = t; } } static dword_t dword_hton(dword_t host) { if (!_rpc_is_bigendian) host = swap_dword_type(host); return host; } static dword_t dword_ntoh(dword_t net) { if (!_rpc_is_bigendian) net = swap_dword_type(net); return net; } static word_t word_hton(word_t host) { if (!_rpc_is_bigendian) host = swap_word_type(host); return host; } static word_t word_ntoh(word_t net) { if (!_rpc_is_bigendian) net = swap_word_type(net); return net; } static qword_t qword_hton(qword_t host) { if (!_rpc_is_bigendian) swap_bytes(&host, sizeof(qword_t)); return host; } static qword_t qword_ntoh(qword_t net) { if (!_rpc_is_bigendian) swap_bytes(&net, sizeof(qword_t)); return net; } static double double_hton(double host) { if (!_rpc_is_bigendian) swap_bytes(&host, sizeof(qword_t)); return host; } static double double_ntoh(double net) { if (!_rpc_is_bigendian) swap_bytes(&net, sizeof(qword_t)); return net; } static float float_hton(float host) { if (!_rpc_is_bigendian) swap_bytes(&host, sizeof(dword_t)); return host; } static float float_ntoh(float net) { if (!_rpc_is_bigendian) swap_bytes(&net, sizeof(dword_t)); return net; } /*============================================================================= Private Functions socket helper functions =============================================================================*/ static int setbufsize(SOCKET s, int rcvlen /*RPC_BUFFSIZE*/, int sndlen /*RPC_BUFFSIZE*/) { int rcv, snd; int rcvl = (int) sizeof(int); int sndl = rcvl; if ( getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*)&rcv, &rcvl)==SOCKET_ERROR || getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char*)&snd, &sndl)==SOCKET_ERROR ) return SOCKET_ERROR; if(rcv < rcvlen){ rcv = rcvlen; rcvl = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*)&rcv, rcvl); assert(rcvl==0); } if(snd < sndlen){ snd = sndlen; sndl = setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char*)&snd, sndl); assert(sndl==0); } return 0; } static int sendmsg(SOCKET s, const char* msgbuf, int msglen, int flags) { int ret; int offset = 0; int left = msglen; while (left > 0) { ret = send(s, &msgbuf[offset], left, flags); if (ret==SOCKET_ERROR || ret==0) return ret; left -= ret; offset = ret; } assert(offset==msglen); return offset; } static int recvmsg(SOCKET s, char* msgbuf, int buflen, int flags) { int ret; int offset = 0; int left = buflen; while (left > 0){ ret = recv(s, &msgbuf[offset], left, flags); if (ret==SOCKET_ERROR || ret==0) return ret; offset = ret; left -= ret; } assert(offset==buflen); return offset; } static BOOL sendbulk(SOCKET s, const char* data, int dataSize, int flags, int maxmsg) { int send, ret; int offset = 0; int left = dataSize; while (left > 0) { send = left>maxmsg? maxmsg:left; ret = sendmsg(s, &data[offset], send, flags); if (ret != send) return FALSE; offset = ret; left -= ret; } return TRUE; } static BOOL recvbulk(SOCKET s, char* buf, int recvlen, int flags, int maxmsg) { int recv, ret; int offset = 0; int left = recvlen; while (left > 0){ recv = left>maxmsg? maxmsg:left; ret = recvmsg(s, &buf[offset], recv, flags); if (ret != recv) return FALSE; offset = ret; left -= ret; } return TRUE; } static LPCSTR errmsg(DWORD dwCode, LPSTR lpszMsgBuf, DWORD dwMsgBufBytes) { FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwCode, 0, /* Default language */ lpszMsgBuf, dwMsgBufBytes, NULL); return lpszMsgBuf; } static void rpc_error_clear(rpc_invoke_error *err) { err->err_type = RPC_NO_ERROR; err->err_code = 0; *err->err_source = 0; *err->err_detail = 0; } // [RESM(4)|总信息字节(4)|err_type(2)|err_code(2)|err_source_size(2)|err_source_string|err_detail_size(2)|err_detail_string] static BOOL rpc_error_short_msg(SOCKET s, char *buf, int size, rpc_invoke_error *err) { int pos = 0; word_t w; ushort err_source_size = (ushort)strlen(err->err_source) 1; ushort err_detail_size = (ushort)strlen(err->err_detail) 1; ulong msglen = 4 4 2 2 2 err_source_size 2 err_detail_size; *buf = 0; assert((ulong)size>=msglen); buf[pos ] = 'R'; buf[pos ] = 'E'; buf[pos ] = 'S'; buf[pos ] = 'M'; msglen = dword_hton(msglen); memcpy(buf pos, &msglen, 4); pos = 4; w = word_hton((word_t)err->err_type); memcpy(buf pos, &w, 2); pos = 2; w = word_hton((word_t)err->err_code); memcpy(buf pos, &w, 2); pos = 2; w = word_hton((word_t)err_source_size); memcpy(buf pos, &w, 2); pos = 2; memcpy(buf pos, err->err_source, err_source_size); pos = err_source_size; w = word_hton((word_t)err_detail_size); memcpy(buf pos, &w, 2); pos = 2; memcpy(buf pos, err->err_detail, err_detail_size); pos = err_detail_size; assert((ulong)pos == dword_ntoh(msglen)); if (pos == (ulong)sendmsg(s, buf, pos, 0)) return TRUE; err->err_type = RPC_SOCKET_ERROR; err->err_code = WSAGetLastError(); *err->err_source = 0; errmsg(err->err_code, err->err_detail, RPC_ERROR_STRING_LEN); return FALSE; } static void debug_out(const char *debug_file, const char *fmt, ...) { #ifdef _DEBUG FILE *fp = 0; va_list ap; fopen_s(&fp, debug_file, "a "); assert(fp); va_start(ap, fmt); vfprintf(fp, fmt, ap); va_end(ap); fclose(fp); #endif } /*============================================================================ RPC PUBLIC FUNCTIONS ============================================================================*/ /** * rpc_throw_error */ RPCRESULT rpc_throw_error(RPC_ERROR_TYPE err_type, LONG err_code, const char* err_source, rpc_invoke_error *err); /** * rpc_invoke_free * 创建RPC调用描述符 */ rpc_invoke_descriptor* rpc_invoke_create(rpc_invoke_descriptor **inv, ushort ordinal, ushort num_params); /** * rpc_invoke_init * 起首化RPC调用描述符 */ rpc_invoke_descriptor * rpc_invoke_init(rpc_invoke_descriptor *inv, ushort ordinal, ushort num_params); /** * rpc_invoke_clear_all * 清除RPC调用描述符, 此后RPC调用描述符能够再度绑定变量 */ void rpc_invoke_clear_all(rpc_invoke_descriptor *inv); /** * rpc_invoke_free * 删除RPC调用描述符, 此后RPC调用描述符将不可用 */ void rpc_invoke_free(rpc_invoke_descriptor *inv); /** * rpc_invoke_set_param * 设置钦定的参数, 重回参数指针 */ rpc_param_descriptor* rpc_invoke_set_param(rpc_invoke_descriptor *inv, ushort id, word_t type); /** * rpc_param_clear * 清除参数内容 */ void rpc_param_clear(rpc_param_descriptor *param); /** * rpc_param_free_list * 清除参数列表内容 */ void rpc_param_free_list(rpc_param_descriptor *param_list, word_t num_params); /** * rpc_connection_create * 创建RPC连接 */ RPCRESULT rpc_connection_create(rpc_connection_descriptor **conn, const char *host, const char *port, long rcvtimeo, rpc_invoke_error *err); /** * rpc_connection_free * 清除RPC连接 */ void rpc_connection_free(rpc_connection_descriptor *conn); /** * rpc_connection_set * 设置RPC连接的属性 */ void rpc_connection_set(rpc_connection_descriptor *conn, dword_t token, dword_t timeout, byte encheader, byte encpackage); /** * rpc_connection_free * 设置输入的参数, 重临参数指针 */ rpc_param_descriptor* rpc_invoke_bind_param(rpc_invoke_descriptor *inv, ushort id, word_t type, void *vaddr, size_t array_size, BOOL is_owner); /** * rpc_connection_free * 总结参数字节总量 */ dword_t rpc_param_get_size(rpc_param_descriptor *param); /** * rpc_connection_free * 计算调用音信的字节总的数量 */ dword_t rpc_invoke_get_size(rpc_invoke_descriptor *inv); /** * rpc_invoke_marshal * 列集全体数量到totalBuf中 */ int rpc_invoke_marshal(rpc_invoke_descriptor *inv, char *totalBuf, int totalSize); /** * rpc_invokehdr_unmarshal * 散集调用头 */ RPCRESULT rpc_invokehdr_unmarshal(SOCKET sClient, dword_t dwToken, char *rpcHdr, int hdrSize, rpc_invoke_descriptor *inv, rpc_invoke_error *err); /** * rpc_invoke_unmarshal * 散集数据到参数中 */ RPCRESULT rpc_invoke_unmarshal(rpc_invoke_descriptor *inv, char *totalBuf, size_t totalSize, rpc_param_descriptor **out_params, word_t *num_params, rpc_invoke_error *err); /** * rpc_param_get_short * 取得短整数参数值 */ void rpc_param_get_short (rpc_param_descriptor *param, SHORT *val); /** * rpc_param_get_ushort * 获得短整数参数值 */ void rpc_param_get_ushort (rpc_param_descriptor *param, USHORT *val); /** * rpc_param_get_long * 取得整数参数值 */ void rpc_param_get_long (rpc_param_descriptor *param, LONG *val); /** * rpc_param_get_ulong * 获得无符号整数参数值 */ void rpc_param_get_ulong (rpc_param_descriptor *param, ULONG *val); /** * rpc_param_get_int * 获得整数参数值 */ void rpc_param_get_int (rpc_param_descriptor *param, INT *val); /** * rpc_param_get_double * 获得双精度参数值 */ void rpc_param_get_double (rpc_param_descriptor *param, double *val); /** * rpc_invoke_send * 发送数据 */ RPCRESULT rpc_invoke_send(rpc_connection_descriptor *conn, rpc_invoke_descriptor *inv, rpc_invoke_error *err); /** * rpc_invoke_recv * 接收数据 */ RPCRESULT rpc_invoke_recv(rpc_connection_descriptor *conn, rpc_invoke_descriptor *outv, rpc_invoke_error *err); /** * rpc_connection_free * 执行RPC调用 */ RPCRESULT rpc_invoke_execute(rpc_connection_descriptor *conn, rpc_invoke_descriptor *inv, rpc_invoke_descriptor *outv, rpc_invoke_error *err); #ifdef __cplusplus } #endif #endif /* _RPCAPI_H__ */

   1: void onMessage(const TcpConnectionPtr& conn,   2:                Buffer* buf,   3:                Timestamp receiveTime)   4: {   5:   if (buf->findCRLF())   6:   {   7:     conn->shutdown();   8:   }   9: }  10:    11: int main()  12: {  13:   EventLoop loop;  14:   TcpServer server(&loop, InetAddress(1079), "Finger");  15:   server.setMessageCallback(onMessage);  16:   server.start();  17:   loop.loop();  18: }
5. 读取客商名、输出错误音讯、然后断开连接 一经读到一行以 结尾的音讯,就发送一条出错音讯,然后断开连接。finger05.cc

1、安装运维情形

    ret = OCIAttrSet((void*)conn->_svc, OCI_HTYPE_SVCCTX, (void*)conn->_srv, 0, OCI_ATTR_SERVER, _err);
    if(ret != OCI_SUCCESS)
    {
        throw Exception(ret, _err, "set SVCCTX attrib failed.");
    }

Here is a Java example:

 

另三个命令行运转

    Environment *env;

    ret = OCIAttrSet((void*)conn->_auth, OCI_HTYPE_SESSION, (void*)user.c_str(), user.size(), OCI_ATTR_USERNAME, _err);
    if(ret != OCI_SUCCESS)
    {
        throw Exception(ret, _err, "set Username attrib failed.");
    }

select bool.val(bool) from tbool where bool = bool.true;

 

   1: typedef std::map UserMap;   2: UserMap users;   3:     4: string getUser(const string& user)   5: {   6:   string result = "No such user";   7:   UserMap::iterator it = users.find(user);   8:   if (it != users.end())   9:   {  10:     result = it->second;  11:   }  12:   return result;  13: }  14:    15: void onMessage(const TcpConnectionPtr& conn,  16:                Buffer* buf,  17:                Timestamp receiveTime)  18: {  19:   const char* crlf = buf->findCRLF();  20:   if (crlf)  21:   {  22:     string user(buf->peek(), crlf);  23:     conn->send(getUser(user) " ");  24:     buf->retrieveUntil(crlf 2);  25:     conn->shutdown();  26:   }  27: }  28:    29: int main()  30: {  31:   users["schen"] = "Happy and well";  32:   EventLoop loop;  33:   TcpServer server(&loop, InetAddress(1079), "Finger");  34:   server.setMessageCallback(onMessage);  35:   server.start();  36:   loop.loop();  37: }
以上正是全体内容,能够用 telnet 扮演客商端来测量试验大家的简易 finger 服务端。

    }

本文由全球彩票平台发布于全球彩票注册平台编程,转载请注明出处:全球彩票注册平台Muduo网络编程示例之四,用户自

TAG标签: 全球彩票平台
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。