Example #1
0
        public IAsyncResult BeginReadPacket(AsyncCallback callback, object stateObject)
        {
            TdsAsyncResult ar = new TdsAsyncResult(callback, stateObject);

            stream.BeginRead(tmpBuf, 0, 8, new AsyncCallback(OnReadPacketCallback), ar);
            return(ar);
        }
Example #2
0
        public void OnReadPacketCallback(IAsyncResult socketAsyncResult)
        {
            TdsAsyncResult ar    = (TdsAsyncResult)socketAsyncResult.AsyncState;
            int            nread = stream.EndRead(socketAsyncResult);
            int            n;

            while (nread < 8)
            {
                n = Read(tmpBuf, nread, 8 - nread);
                if (n <= 0)
                {
                    socket = null;
                    stream.Close();
                    throw new IOException(n == 0 ? "Connection lost" : "Connection error");
                }
                nread += n;
            }

            TdsPacketType packetType = (TdsPacketType)tmpBuf[0];

            if (packetType != TdsPacketType.Logon && packetType != TdsPacketType.Query && packetType != TdsPacketType.Reply)
            {
                throw new Exception(String.Format("Unknown packet type {0}", tmpBuf[0]));
            }

            // figure out how many bytes are remaining in this packet.
            int len = Ntohs(tmpBuf, 2) - 8;

            if (len >= inBuffer.Length)
            {
                inBuffer = new byte[len];
            }

            if (len < 0)
            {
                throw new Exception(String.Format("Confused by a length of {0}", len));
            }

            GetPhysicalPacketData(len);
            int value = len + 8;

            ar.ReturnValue = ((object)value);             // packet size
            ar.MarkComplete();
        }
Example #3
0
                public IAsyncResult BeginReadPacket (AsyncCallback callback, object stateObject)
		{
                        TdsAsyncResult ar = new TdsAsyncResult (callback, stateObject);

                        stream.BeginRead (tmpBuf, 0, 8, new AsyncCallback(OnReadPacketCallback), ar);
                        return ar;
		}
Example #4
0
File: Tds.cs Project: psni/mono
                protected IAsyncResult BeginExecuteQueryInternal (string sql, bool wantResults, 
                                                          AsyncCallback callback, object state)
                {
			InitExec ();

                        TdsAsyncResult ar = new TdsAsyncResult (callback, state);
                        ar.TdsAsyncState.WantResults = wantResults;

			Comm.StartPacket (TdsPacketType.Query);
			Comm.Append (sql);
			try {
				Comm.SendPacket ();
				Comm.BeginReadPacket (new AsyncCallback(OnBeginExecuteQueryCallback), 
						      ar);
			} catch (IOException ex) {
				connected = false;
				throw new TdsInternalException ("Server closed the connection.", ex);
			}

                        return ar;
                }
Example #5
0
                protected IAsyncResult BeginExecuteQueryInternal (string sql, bool wantResults, 
                                                          AsyncCallback callback, object state)
                {
                        moreResults = true;
			doneProc = false;
			messages.Clear ();
			outputParameters.Clear ();

                        TdsAsyncResult ar = new TdsAsyncResult (callback, state);
                        ar.TdsAsyncState.WantResults = wantResults;

			Comm.StartPacket (TdsPacketType.Query);
			Comm.Append (sql);
			Comm.SendPacket ();

                        Comm.BeginReadPacket (new AsyncCallback(OnBeginExecuteQueryCallback), 
                                                                    ar);
                        return ar;
                }