Ejemplo n.º 1
0
 internal void FlushBatchNqData()
 {
     if (batchnqbuflen > 0)
     {
         netstm.WriteByte((byte)'N'); // Batched non-query.
         XContent.SendXContent(netstm, batchnqbuf, batchnqbuflen);
         int ib = netstm.ReadByte();
         if (ib == (byte)'-')
         {
             string errmsg = XContent.ReceiveXString(netstm, buf);
             throw new Exception("ExecuteNonQuery error: " + errmsg);
         }
         if (ib != (byte)'+')
         {
             throw new Exception("ExecuteNonQuery did not receive a success signal from service.");
         }
     }
     batchnqbuflen = 0;
 }
Ejemplo n.º 2
0
        public override void Open()
        {
            if (isRIndexEnabled())
            {
                _OpenRIndex();
                return;
            }

            try
            {
                if (state == ConnectionState.Open)
                {
                    throw new Exception("Connnection is already open.");
                }

                string[] hosts = connstr.DataSource;
                Random   rnd   = new Random(unchecked (System.DateTime.Now.Millisecond + System.Threading.Thread.CurrentThread.ManagedThreadId));
                int      index = rnd.Next() % hosts.Length;
                string   host  = hosts[index];
                for (int startindex = index; ;)
                {
                    try
                    {
                        sock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                        sock.Connect(host, 55902);
                        break;
                    }
                    catch
                    {
                        sock.Close();
                        index++;
                        if (index == hosts.Length)
                        {
                            index = 0;
                        }
                        if (index == startindex)
                        {
                            throw;
                        }
                        host = hosts[index];
                    }
                }
                netstm = new System.Net.Sockets.NetworkStream(sock);
                netstm.WriteByte((byte)'o'); //Open connection.
                if (buf.Length < 128)
                {
                    buf = new byte[128];
                }
                Utils.Int64ToBytes(connstr.BatchSize, buf, 0);
                XContent.SendXContent(netstm, buf, 8);
                {
                    int optindex = 0;
                    Utils.Int64ToBytes(connstr.BlockSize, buf, optindex);
                    optindex += 8;
                    Utils.Int32ToBytes(connstr.QOLimit, buf, optindex);
                    optindex     += 4;
                    buf[optindex] = (byte)(connstr.FaultTolerantExecution ? 1 : 0);
                    optindex     += 1;
                    XContent.SendXContent(netstm, buf, optindex);
                }
                XContent.SendXContent(netstm, string.Join(";", hosts));

                if (netstm.ReadByte() != (byte)'+')
                {
                    throw new Exception("Cannot connect to host.  Handshake failed with protocol.");
                }
                sessionID = XContent.ReceiveXString(netstm, buf);
                state     = ConnectionState.Open;
            }
            catch
            {
                Cleanup();
                throw;
            }
        }