コード例 #1
0
ファイル: MReadBlob.cs プロジェクト: Galigator/db4o
		/// <exception cref="System.IO.IOException"></exception>
		public override void ProcessClient(Socket4Adapter sock)
		{
			Msg message = Msg.ReadMessage(MessageDispatcher(), Transaction(), sock);
			if (message.Equals(Msg.Length))
			{
				try
				{
					_currentByte = 0;
					_length = message.PayLoad().ReadInt();
					_blob.GetStatusFrom(this);
					_blob.SetStatus(Status.Processing);
					Copy(sock, this._blob.GetClientOutputStream(), _length, true);
					message = Msg.ReadMessage(MessageDispatcher(), Transaction(), sock);
					if (message.Equals(Msg.Ok))
					{
						this._blob.SetStatus(Status.Completed);
					}
					else
					{
						this._blob.SetStatus(Status.Error);
					}
				}
				catch (Exception)
				{
				}
			}
			else
			{
				if (message.Equals(Msg.Error))
				{
					this._blob.SetStatus(Status.Error);
				}
			}
		}
コード例 #2
0
ファイル: MsgBlob.cs プロジェクト: erdincay/db4o
		/// <exception cref="System.IO.IOException"></exception>
		protected virtual void Copy(Socket4Adapter sock, IOutputStream rawout, int length
			, bool update)
		{
			BufferedOutputStream @out = new BufferedOutputStream(rawout);
			byte[] buffer = new byte[BlobImpl.CopybufferLength];
			int totalread = 0;
			while (totalread < length)
			{
				int stilltoread = length - totalread;
				int readsize = (stilltoread < buffer.Length ? stilltoread : buffer.Length);
				int curread = sock.Read(buffer, 0, readsize);
				if (curread < 0)
				{
					throw new IOException();
				}
				@out.Write(buffer, 0, curread);
				totalread += curread;
				if (update)
				{
					_currentByte += curread;
				}
			}
			@out.Flush();
			@out.Close();
		}
コード例 #3
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void ProcessClient(Socket4Adapter sock)
		{
			Msg message = Msg.ReadMessage(MessageDispatcher(), Transaction(), sock);
			if (message.Equals(Msg.Ok))
			{
				try
				{
					_currentByte = 0;
					_length = this._blob.GetLength();
					_blob.GetStatusFrom(this);
					_blob.SetStatus(Status.Processing);
					FileInputStream inBlob = this._blob.GetClientInputStream();
					Copy(inBlob, sock, true);
					sock.Flush();
					message = Msg.ReadMessage(MessageDispatcher(), Transaction(), sock);
					if (message.Equals(Msg.Ok))
					{
						// make sure to load the filename to i_blob
						// to allow client databasefile switching
						Container().Deactivate(Transaction(), _blob, int.MaxValue);
						Container().Activate(Transaction(), _blob, new FullActivationDepth());
						this._blob.SetStatus(Status.Completed);
					}
					else
					{
						this._blob.SetStatus(Status.Error);
					}
				}
				catch (Exception e)
				{
					Sharpen.Runtime.PrintStackTrace(e);
				}
			}
		}
コード例 #4
0
 /// <exception cref="System.Exception"></exception>
 public virtual void SetUp()
 {
     _serverSocket = _plainSocketFactory.CreateServerSocket(0);
     _port = _serverSocket.GetLocalPort();
     _client = new Socket4Adapter(_plainSocketFactory.CreateSocket("localhost", _port)
         );
     _server = new Socket4Adapter(_serverSocket.Accept());
 }
コード例 #5
0
 internal ClientMessageDispatcherImpl(ClientObjectContainer client, Socket4Adapter
     a_socket, BlockingQueue synchronousMessageQueue, BlockingQueue asynchronousMessageQueue
     )
 {
     _container = client;
     _synchronousMessageQueue = synchronousMessageQueue;
     _asynchronousMessageQueue = asynchronousMessageQueue;
     _socket = a_socket;
 }
コード例 #6
0
		/// <exception cref="System.Exception"></exception>
		internal ServerMessageDispatcherImpl(ObjectServerImpl server, ClientTransactionHandle
			 transactionHandle, ISocket4 socket4, int threadID, bool loggedIn, object mainLock
			)
		{
			_mainLock = mainLock;
			_transactionHandle = transactionHandle;
			_loggedin = loggedIn;
			_server = server;
			_threadID = threadID;
			_socket = new Socket4Adapter(socket4);
			_socket.SetSoTimeout(((Config4Impl)server.Configure()).TimeoutServerSocket());
		}
コード例 #7
0
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		/// <exception cref="Db4objects.Db4o.Ext.OldFormatException"></exception>
		/// <exception cref="Db4objects.Db4o.Ext.InvalidPasswordException"></exception>
		public virtual IObjectContainer OpenClient(IClientConfiguration clientConfig, string
			 hostName, int port, string user, string password)
		{
			if (user == null || password == null)
			{
				throw new InvalidPasswordException();
			}
			Config4Impl config = AsLegacy(clientConfig);
			Config4Impl.AssertIsNotTainted(config);
			Socket4Adapter networkSocket = new Socket4Adapter(clientConfig.Networking.SocketFactory
				, hostName, port);
			return new ClientObjectContainer(clientConfig, networkSocket, user, password, true
				);
		}
コード例 #8
0
ファイル: MsgBlob.cs プロジェクト: Galigator/db4o
		/// <exception cref="System.IO.IOException"></exception>
		protected virtual void Copy(IInputStream rawin, Socket4Adapter sock, bool update)
		{
			BufferedInputStream @in = new BufferedInputStream(rawin);
			byte[] buffer = new byte[BlobImpl.CopybufferLength];
			int bytesread = -1;
			while ((bytesread = rawin.Read(buffer)) >= 0)
			{
				sock.Write(buffer, 0, bytesread);
				if (update)
				{
					_currentByte += bytesread;
				}
			}
			@in.Close();
		}
コード例 #9
0
 public ClientObjectContainer(ClientConfigurationImpl config, Socket4Adapter socket
     , string user, string password, bool login) : base(Db4oClientServerLegacyConfigurationBridge
         .AsLegacy(config))
 {
     // Db4o.registerClientConstructor(new ClientConstructor());
     _userName = user;
     _password = password;
     _login = login;
     _heartbeat = new ClientHeartbeat(this);
     _classInfoHelper = new ClassInfoHelper(Db4oClientServerLegacyConfigurationBridge.
         AsLegacy(config));
     SetAndConfigSocket(socket);
     Open();
     config.ApplyConfigurationItems(this);
 }
コード例 #10
0
ファイル: MsgD.cs プロジェクト: erdincay/db4o
		internal sealed override Msg ReadPayLoad(IMessageDispatcher messageDispatcher, Transaction
			 a_trans, Socket4Adapter sock, ByteArrayBuffer reader)
		{
			int length = reader.ReadInt();
			a_trans = CheckParentTransaction(a_trans, reader);
			Db4objects.Db4o.CS.Internal.Messages.MsgD command = (Db4objects.Db4o.CS.Internal.Messages.MsgD
				)PublicClone();
			command.SetTransaction(a_trans);
			command.SetMessageDispatcher(messageDispatcher);
			command._payLoad = ReadMessageBuffer(a_trans, sock, length);
			return command;
		}
コード例 #11
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void ProcessClient(Socket4Adapter sock)
		{
		}
コード例 #12
0
 /// <exception cref="System.Exception"></exception>
 private void AssertReadClose(Socket4Adapter socketToBeClosed, ICodeBlock codeBlock
     )
 {
     var thread = new CatchAllThread
         (codeBlock);
     thread.EnsureStarted();
     socketToBeClosed.Close();
     thread.Join();
     Assert.IsInstanceOf(typeof (Db4oIOException), thread.Caught());
 }
コード例 #13
0
ファイル: MsgBlob.cs プロジェクト: erdincay/db4o
		/// <exception cref="System.IO.IOException"></exception>
		public abstract void ProcessClient(Socket4Adapter socket);
コード例 #14
0
		private void SetAndConfigSocket(Socket4Adapter socket)
		{
			_socket = socket;
			_socket.SetSoTimeout(_config.TimeoutClientSocket());
		}
コード例 #15
0
		/// <exception cref="Db4objects.Db4o.Ext.InvalidPasswordException"></exception>
		private void LoginToServer(Socket4Adapter iSocket)
		{
			UnicodeStringIO stringWriter = new UnicodeStringIO();
			int length = stringWriter.Length(_userName) + stringWriter.Length(_password);
			MsgD message = Msg.Login.GetWriterForLength(SystemTransaction(), length);
			message.WriteString(_userName);
			message.WriteString(_password);
			message.Write(iSocket);
			Msg msg = ReadLoginMessage(iSocket);
			ByteArrayBuffer payLoad = msg.PayLoad();
			BlockSize(payLoad.ReadInt());
			int doEncrypt = payLoad.ReadInt();
			if (doEncrypt == 0)
			{
				_handlers.OldEncryptionOff();
			}
			if (payLoad.RemainingByteCount() > 0)
			{
				_serverSideID = payLoad.ReadInt();
			}
		}
コード例 #16
0
ファイル: Msg.cs プロジェクト: bvangrinsven/db4o-net
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		protected static StatefulBuffer ReadMessageBuffer(Db4objects.Db4o.Internal.Transaction
			 trans, Socket4Adapter socket)
		{
			return ReadMessageBuffer(trans, socket, Const4.MessageLength);
		}
コード例 #17
0
ファイル: Msg.cs プロジェクト: bvangrinsven/db4o-net
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		protected static StatefulBuffer ReadMessageBuffer(Db4objects.Db4o.Internal.Transaction
			 trans, Socket4Adapter socket, int length)
		{
			StatefulBuffer buffer = new StatefulBuffer(trans, length);
			int offset = 0;
			while (length > 0)
			{
				int read = socket.Read(buffer._buffer, offset, length);
				if (read < 0)
				{
					throw new Db4oIOException();
				}
				offset += read;
				length -= read;
			}
			return buffer;
		}
コード例 #18
0
ファイル: Msg.cs プロジェクト: bvangrinsven/db4o-net
		public virtual bool Write(Socket4Adapter sock)
		{
			if (null == sock)
			{
				throw new ArgumentNullException();
			}
			lock (sock)
			{
				try
				{
					sock.Write(PayLoad()._buffer);
					sock.Flush();
					return true;
				}
				catch (Exception)
				{
					// TODO: .NET convert SocketException to Db4oIOException
					// and let Db4oIOException bubble up.
					//e.printStackTrace();
					return false;
				}
			}
		}
コード例 #19
0
ファイル: Msg.cs プロジェクト: bvangrinsven/db4o-net
		/// <param name="socket"></param>
		internal virtual Db4objects.Db4o.CS.Internal.Messages.Msg ReadPayLoad(IMessageDispatcher
			 messageDispatcher, Db4objects.Db4o.Internal.Transaction a_trans, Socket4Adapter
			 socket, ByteArrayBuffer reader)
		{
			Db4objects.Db4o.CS.Internal.Messages.Msg msg = PublicClone();
			msg.SetMessageDispatcher(messageDispatcher);
			msg.SetTransaction(CheckParentTransaction(a_trans, reader));
			return msg;
		}
コード例 #20
0
ファイル: Msg.cs プロジェクト: bvangrinsven/db4o-net
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		public static Db4objects.Db4o.CS.Internal.Messages.Msg ReadMessage(IMessageDispatcher
			 messageDispatcher, Db4objects.Db4o.Internal.Transaction trans, Socket4Adapter socket
			)
		{
			StatefulBuffer reader = ReadMessageBuffer(trans, socket);
			Db4objects.Db4o.CS.Internal.Messages.Msg message = _messages[reader.ReadInt()].ReadPayLoad
				(messageDispatcher, trans, socket, reader);
			return message;
		}
コード例 #21
0
		public ClientObjectContainer(IClientConfiguration config, Socket4Adapter socket, 
			string user, string password, bool login) : this((ClientConfigurationImpl)config
			, socket, user, password, login)
		{
		}
コード例 #22
0
 public ClientObjectContainer(IClientConfiguration config, Socket4Adapter socket,
                              string user, string password, bool login) : this((ClientConfigurationImpl)config
                                                                               , socket, user, password, login)
 {
 }
コード例 #23
0
		private void StartDispatcherThread(Socket4Adapter socket, string user)
		{
			if (!_singleThreaded)
			{
				StartAsynchronousMessageProcessor();
			}
			ClientMessageDispatcherImpl dispatcherImpl = new ClientMessageDispatcherImpl(this
				, socket, _synchronousMessageQueue, _asynchronousMessageQueue);
			string dispatcherName = "db4o client side message dispatcher for " + user;
			_messageDispatcher = dispatcherImpl;
			ThreadPool().Start(dispatcherName, dispatcherImpl);
		}
コード例 #24
0
 private void SetAndConfigSocket(Socket4Adapter socket)
 {
     _socket = socket;
     _socket.SetSoTimeout(_config.TimeoutClientSocket());
 }
コード例 #25
0
		private Msg ReadLoginMessage(Socket4Adapter iSocket)
		{
			Msg msg = Msg.ReadMessage(this, SystemTransaction(), iSocket);
			while (Msg.Pong.Equals(msg))
			{
				msg = Msg.ReadMessage(this, SystemTransaction(), iSocket);
			}
			if (!Msg.LoginOk.Equals(msg))
			{
				throw new InvalidPasswordException();
			}
			return msg;
		}
コード例 #26
0
 private void AssertWriteClose(Socket4Adapter socketToBeClosed, ICodeBlock codeBlock
     )
 {
     socketToBeClosed.Close();
     Assert.Expect(typeof (Db4oIOException), new _ICodeBlock_102(codeBlock));
 }