cdrserver.cpp

来自「MySQL数据库开发源码 值得一看哦」· C++ 代码 · 共 1,492 行 · 第 1/5 页

CPP
1,492
字号
					error_handler(MyTransaction->getNdbErrorString());                                tmpcdrptr->USED_FIELDS |= B_START_TIME;				#ifdef SETDBG					puts("USED_FIELDS");				#endif				check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);				if (check == -1)					error_handler(MyTransaction->getNdbErrorString());                        break;                        case 1:                                tmpcdrptr->OurTimeForStartOfCharge = ourtime;				#ifdef SETDBG					puts("OurStartOfCharge");				#endif				check = MyOperation->setValue("OurStartOfCharge",(char*)&tmpcdrptr->OurTimeForStartOfCharge);				if (check == -1)					error_handler(MyTransaction->getNdbErrorString());                                tmpcdrptr->USED_FIELDS |= B_TimeForStartOfCharge;				#ifdef SETDBG					puts("USED_FIELDS");				#endif				check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);				if (check == -1)					error_handler(MyTransaction->getNdbErrorString());                        break;                        case 2:                                tmpcdrptr->OurTimeForStopOfCharge = ourtime;				#ifdef SETDBG					puts("OurStopOfCharge");				#endif				check = MyOperation->setValue("OurStopOfCharge",(char*)&tmpcdrptr->OurTimeForStopOfCharge);				if (check == -1)					error_handler(MyTransaction->getNdbErrorString());                                tmpcdrptr->USED_FIELDS |= B_TimeForStopOfCharge;				#ifdef SETDBG					puts("USED_FIELDS");				#endif				check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);				if (check == -1)					error_handler(MyTransaction->getNdbErrorString());                        break;                        case 3:                                tmpcdrptr->CallAttemptState  = 4;                        break;			default:        			snprintf(msg,sizeof(msg),"cdrtype %d unknown",cdrsubtype);				if ((checkchangelog(log,lognamn))==0)          				n2log(log,msg);                                goto errout;                        break;                }                                ops++;                                if (ops == ops_before_exe) {                                  ops = 0;                                  #ifdef SETDBG                                        puts("Going to execute");                                  #endif                                  check = MyTransaction->execute(Commit, CommitAsMuchAsPossible);                		  if ((check == -1) && (MyTransaction->getNdbError() != 0))                                        error_handler(MyTransaction->getNdbErrorString());                                  MyNdb.closeTransaction(MyTransaction);                                  #ifdef SETDBG                                        puts("Transaction closed");                                  #endif                                  #ifdef SETDBG                                        puts("New transaction initiated");                                  #endif                                }//if                /* Increment the request count. */                reqcnt++;                /* Send a response back to the client. */                /* if (send(s, buf, 10, 0) != 10) goto errout;  */        }        /* The loop has terminated, because there are no                */        /* more requests to be serviced. As mentioned above,            */        /* this close will block until all of the sent replies          */        /* have been received by the remote host. The reason            */        /* for lingering on the close is so that the server will        */        /* have a better idea of when the remote has picked up          */        /* all of the data. This will allow the start and finish        */        /* times printed in the log file to reflect more accurately     */        /* the length of time this connection was                       */        /* The port number must be converted first to host byte         */        /* order before printing. On most hosts, this is not            */        /* necessary, but the ntohs() call is included here so          */        /* that this program could easily be ported to a host           */        /* that does require it.                                        */        BaseString::snprintf(msg,sizeof(msg),"Completed %s port %u, %d requests",hostname,ntohs(peeraddr_in.sin_port), reqcnt);	if ((checkchangelog(fi,temp))==0)          c2log(fi,msg);	error_from_client = 1;        BaseString::snprintf(msg,sizeof(msg),"Communicate with threads");	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);        BaseString::snprintf(msg,sizeof(msg),"Waiting for threads to return from work");	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);        BaseString::snprintf(msg,sizeof(msg),"Closing down");	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);        close(s);        fclose(log);        return EXIT_SUCCESS;errout:        BaseString::snprintf(msg,sizeof(msg),"Connection with %s aborted on error\n", hostname);	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);	if ((checkchangelog(fi,temp))==0)          c2log(fi,msg);	error_from_client = 1;        BaseString::snprintf(msg,sizeof(msg),"Communicate with threads");	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);        BaseString::snprintf(msg,sizeof(msg),"Waiting for threads to return from work");	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);        BaseString::snprintf(msg,sizeof(msg),"Closing down");	if ((checkchangelog(log,lognamn))==0)          n2log(log,msg);        close(s);        fclose(log);	return EXIT_FAILURE;}voidcreate_table(Ndb* pMyNdb){ /****************************************************************   *    Create table and attributes.   *   *    create table basictab1(   *        col1 int,   *        col2 int not null,   *        col3 int not null,   *        col4 int not null   *     )   *    ***************************************************************/  int                   check;  int                   i;  NdbSchemaCon          *MySchemaTransaction;  NdbSchemaOp           *MySchemaOp;  int			tAttributeSize;  tAttributeSize = 1;  cout << "Creating " << tableName << "..." << endl;   MySchemaTransaction = pMyNdb->startSchemaTransaction();   if( MySchemaTransaction == NULL )      error_handler(MySchemaTransaction->getNdbErrorString());   MySchemaOp = MySchemaTransaction->getNdbSchemaOp();   if( MySchemaOp == NULL )      error_handler(MySchemaTransaction->getNdbErrorString());   // Createtable   check = MySchemaOp->createTable( tableName,                                     8,         // Table Size                                     TupleKey,  // Key Type                                     40         // Nr of Pages                                   );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());   // CallIdentificationNumber Create first column, primary key    check = MySchemaOp->createAttribute( "CIN", 					TupleKey, 					32,                                        tAttributeSize,					UnSigned, MMBased,                                        NotNullAttribute 					);   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());     // USED_FIELDS Create attributes   check = MySchemaOp->createAttribute( "USED_FIELDS", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // ClientId Create attributes   check = MySchemaOp->createAttribute( "ClientId", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // START_TIME Create attributes   check = MySchemaOp->createAttribute( "START_TIME", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // OurSTART_TIME Create attributes   check = MySchemaOp->createAttribute( "OurSTART_TIME", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // TimeForStartOfCharge Create attributes   check = MySchemaOp->createAttribute( "StartOfCharge", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // TimeForStopOfCharge Create attributes   check = MySchemaOp->createAttribute( "StopOfCharge", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // OurTimeForStartOfCharge Create attributes   check = MySchemaOp->createAttribute( "OurStartOfCharge", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // OurTimeForStopOfCharge Create attributes   check = MySchemaOp->createAttribute( "OurStopOfCharge", NoKey, 32,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // DestinationPointCode Create attributes   check = MySchemaOp->createAttribute( "DPC", NoKey, 16,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // OriginatingPointCode Create attributes   check = MySchemaOp->createAttribute( "OPC", NoKey, 16,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // CircuitIdentificationCode Create attributes   check = MySchemaOp->createAttribute( "CIC", NoKey, 16,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // ReroutingIndicator Create attributes   check = MySchemaOp->createAttribute( "RI", NoKey, 16,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // RINParameter Create attributes   check = MySchemaOp->createAttribute( "RINParameter", NoKey, 16,                                         tAttributeSize, UnSigned, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // NetworkIndicator Create attributes   check = MySchemaOp->createAttribute( "NIndicator", NoKey, 8,                                         tAttributeSize, Signed, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // CallAttemptState Create attributes   check = MySchemaOp->createAttribute( "CAS", NoKey, 8,                                         tAttributeSize, Signed, MMBased,                                         NullAttribute );   if( check == -1 )      error_handler(MySchemaTransaction->getNdbErrorString());    // ACategory Create attributes   check = MySchemaOp->createAttribute( "ACategory", NoKey, 8,                                         tA

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?