예제 #1
0
 public OktoResultCodes RegisterMessageSupport(Connection conn, FuncPtrSerialize funcPtrSerialize, uint seqNo)
 {
     int countBytesToSend = funcPtrSerialize(conn.sendBuffer, 0);
     int countBytesSent = conn.Send(conn.sendBuffer, 0, countBytesToSend);
     if (countBytesSent != countBytesToSend)
     {
         Console.WriteLine("SendMessageRegister Err: attempt {0} sent {1}.", countBytesToSend, countBytesSent);
         return OktoResultCodes.OKTO_RESULT_SOCK_ERROR;
     }
     int countRecv = conn.Recv(conn.receiveBuffer, 0, (int)MessageAck.TOTAL_MESSAGE_SIZE);
     if (countRecv != MessageAck.TOTAL_MESSAGE_SIZE)
     {
         Console.WriteLine("SendMessageRegister Err: attempt {0} recv {1}.", MessageAck.TOTAL_MESSAGE_SIZE, countRecv);
         return OktoResultCodes.OKTO_RESULT_INVALID_MESSAGE_LENGTH;
     }
     MessageAck ack = MessageAck.CreateFromNetBytes(conn.receiveBuffer, 0);
     //Console.WriteLine("SendSynchronous rcv MessageAck({0},{1})", ack.SeqNo, ack.Result);
     if (ack.SeqNo != seqNo)
     {
         Console.WriteLine("SendMessageRegister Err: SN {0} != expected {1}.", ack.SeqNo, seqNo);
         return OktoResultCodes.OKTO_RESULT_INVALID_MESSAGE;
     }
     else if (ack.Result != (uint)OktoResultCodes.OKTO_RESULT_SUCCESS)
     {
         Console.WriteLine("SendMessageRegister Err: TID {0} not available", TenantId);
     }
     return (OktoResultCodes)ack.Result;
 }
 /// <summary>
 /// Send given message on given connection then block until a (n)ack is received.
 /// </summary>
 /// <param name="conn">Connection (think TCP to specific network agent) on which message is to be sent.</param>
 /// <param name="funcPtrSerialize"></param>
 /// <returns></returns>
 private bool SendSequential(Connection conn, FuncPtrSerialize funcPtrSerialize, uint seqNo)
 {
     int countBytesToSend = funcPtrSerialize(conn.sendBuffer, 0);
     int countBytesSent = conn.Send(conn.sendBuffer, 0, countBytesToSend);
     if (countBytesSent != countBytesToSend)
     {
         Console.WriteLine("SendSynchronous Err: attempt {0} sent {1}.", countBytesToSend, countBytesSent);
         return false;
     }
     int countRecv = conn.Recv(conn.receiveBuffer, 0, (int)MessageAck.TOTAL_MESSAGE_SIZE);
     if (countRecv != MessageAck.TOTAL_MESSAGE_SIZE)
     {
         Console.WriteLine("SendSynchronous Err: attempt {0} recv {1}.", MessageAck.TOTAL_MESSAGE_SIZE, countRecv);
         return false;
     }
     conn.MessageAck.InitFromNetBytes(conn.receiveBuffer, 0);
     Console.WriteLine("SendSynchronous rcv MessageAck({0},{1})", conn.MessageAck.SeqNo, conn.MessageAck.Result);
     if (conn.MessageAck.SeqNo != seqNo)
     {
         Console.WriteLine("SendSynchronous Err: SN {0} != expected {1}.", conn.MessageAck.SeqNo, seqNo);
         return false;
     }
     return true;
 }