bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Blocking IO


From: Jon Wilson
Subject: Blocking IO
Date: Mon, 17 Mar 2003 11:53:37 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2.1) Gecko/20021130

Jon Wilson wrote:

When passing a tcpstream to a function requiring an iostream and using the >> and << operators, the io doesn't seem to block on reading??? I have a program with one thread, the idea is that each sends a receives data to and from each other, and that each requires the data just sent by the other in order to send their next message (the messages MUST be interleaved). However, on calling the >> operator, the IO doesn't seem to block! I have looked at the trace of my program and one thread seems to continue running past the point it requires input before the other has started. Is there a way to make the tcpstream block for input using the insertion operators? Or any other way? I attach a fragment of code. As you can see, both spend and receive should be called at the same time, both reading/writing to the same network socket.
Hope someone can help with this as it is for an important project.
Thanks.
Jon Wilson
N.B: All insertion operators for defined types use the string insertion method defined in std c++.
Thread....
void run(){
           try{
               tcpstream tcp("127.0.0.1:9000");
               dc.receive(tcp);
               tcp.close();
           }catch(Botan::Exception& e){
               cout << e.what();
           }catch(...){
               cout << "Some other error" << endl;
           }
       }
Main code....
TCPSocket tcp("127.0.0.1",9000);
       myThread thread;
       while(!tcp.isPendingConnection());
       tcpstream stream(tcp);
       dc.spend(stream);
       stream.close();

void OwnDigitalCash::spend(iostream& io){
   RSA_PublicKey pub(*priv);
   cout << "Sending public Key" << endl;
   io << &pub << endl;
   cout << "Sending this" << endl;
   io << *this << endl;
   if(priv==NULL)cout << "NULL" << endl;
cout << "Q " << priv->get_q() << endl << "P " << priv->get_p() << endl << "D " << priv->get_d() << endl; cout << "N " << priv->get_n() << endl << "E " << priv->get_e() << endl;
   BitCommiter bc(*priv);

   SecureVector<Botan::byte> lb;
   SecureVector<Botan::byte> rb;
     for(int i=0;i<IDENTITYPAIRS;i++){
       cout << "Spend " << i << endl;
       lb << leftEncryptedKey[i];
       rb << rightEncryptedKey[i];
       string lk;
       string rk;
       cout << "Decrypting keys" << endl;
       lk << bc.reveal(lb).value();
       rk << bc.reveal(rb).value();
       cout << lk << endl << rk << endl;
       cout << "Constructing oblivious sender" << endl;
       ObliviousSender ots(*priv);
       cout << "Secding keys" << endl;
       io << ots.getKey(LEFT) << endl;
       io << ots.getKey(RIGHT) << endl;
       cout << "Receiving Key and IV" << endl;
       SecureVector<Botan::byte> ek;
       SecureVector<Botan::byte> eiv;
       io >> ek;
       io >> eiv;
       cout << "EK2 " << ek << endl;
       cout << "EIV2 "<< eiv << endl;
       cout << "Decrypting Key" << endl;
       ots.decryptKey(ek,eiv);
       ots.setMessages(lk,rk);
       cout << "Sending data" << endl;
       io << ots.getIV() << endl;
       io << ots.getEncryptedMessage(LEFT) << endl;
       io << ots.getEncryptedMessage(RIGHT) << endl;
   }
}
void ReceivedDigitalCash::receive(iostream& io){
   cout << "Receive" << endl;
   io >> pub;
   cout << "Received public key" << endl;
   cout << "Receiving this" << endl;
   *this<<io;
   cout << "Received this" << endl;
     for(int i=0;i<IDENTITYPAIRS;i++){
       cout << "Receive " << i << endl;
       ObliviousReceiver otr(*pub);
       cout << "Constructed Receiver" << endl;
       SymmetricKey skl;
       SymmetricKey skr;
       cout << "Reading Symmetric Keys" << endl;
       io >> skl;
       io >> skr;
       cout << skl << endl << skr << endl;
       otr.setKey(LEFT,skl);
       otr.setKey(RIGHT,skr);
       cout << "Sending Key and IV" << endl;
       cout << "EK1 "<< otr.encryptKey() << endl;
       cout << "EIV1 "<< otr.getIV() << endl;
       io << otr.encryptKey() << endl;
       io << otr.getIV() << endl;
       BlockCipherModeIV iv;
       string left;
       string right;
       cout << "Receiving messages" << endl;
       io >> iv;
       io >> left;
       io >> right;
       string dec=otr.decryptMessage(iv,left,right);
       cout << "Getting half" << endl;
       half h=otr.getHalf();
       SecureVector<Botan::byte> sym;
       cout << "Converting to Symmetric Key" << endl;
       sym << dec;

       SymmetricKey symKey(sym);
             CommitmentChecker cc(symKey);
       cc.setR1(r1);
       BlockCipherModeIV ivBC;
       ivBC << (h==LEFT?leftMessageIV[i]:rightMessageIV[i]);
       cc.setMessageIV(ivBC);
cc.setEncryptedMessage(h==LEFT?leftEncryptedMessage[i]:rightEncryptedMessage[i]);
       cc.setHashedValue(h==LEFT?leftHashedValue[i]:rightHashedValue[i]);
       decryptedIdentity[i]=cc.checkCommitment();
   }
}







reply via email to

[Prev in Thread] Current Thread [Next in Thread]