/// <exception cref="System.IO.IOException"></exception> public override void ProcessClient(Socket4Adapter sock) { var message = ReadMessage(MessageDispatcher(), Transaction(), sock); if (message.Equals(Length)) { try { _currentByte = 0; _length = message.PayLoad().ReadInt(); _blob.GetStatusFrom(this); _blob.SetStatus(Status.Processing); Copy(sock, _blob.GetClientOutputStream(), _length, true); message = ReadMessage(MessageDispatcher(), Transaction(), sock); if (message.Equals(Ok)) { _blob.SetStatus(Status.Completed); } else { _blob.SetStatus(Status.Error); } } catch (Exception) { } } else { if (message.Equals(Error)) { _blob.SetStatus(Status.Error); } } }
/// <exception cref="System.IO.IOException"></exception> public override void ProcessClient(Socket4Adapter sock) { var message = ReadMessage(MessageDispatcher(), Transaction(), sock); if (message.Equals(Ok)) { try { _currentByte = 0; _length = _blob.GetLength(); _blob.GetStatusFrom(this); _blob.SetStatus(Status.Processing); var inBlob = _blob.GetClientInputStream(); Copy(inBlob, sock, true); sock.Flush(); message = ReadMessage(MessageDispatcher(), Transaction(), sock); if (message.Equals(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()); _blob.SetStatus(Status.Completed); } else { _blob.SetStatus(Status.Error); } } catch (Exception e) { Runtime.PrintStackTrace(e); } } }
/// <exception cref="System.IO.IOException"></exception> protected virtual void Copy(Socket4Adapter sock, IOutputStream rawout, int length , bool update) { var @out = new BufferedOutputStream(rawout); var buffer = new byte[BlobImpl.CopybufferLength]; var totalread = 0; while (totalread < length) { var stilltoread = length - totalread; var readsize = (stilltoread < buffer.Length ? stilltoread : buffer.Length); var 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(); }
/// <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(); } var config = AsLegacy(clientConfig); Config4Impl.AssertIsNotTainted(config); var networkSocket = new Socket4Adapter(clientConfig.Networking.SocketFactory , hostName, port); return new ClientObjectContainer(clientConfig, networkSocket, user, password, true ); }
/// <exception cref="System.IO.IOException"></exception> protected virtual void Copy(IInputStream rawin, Socket4Adapter sock, bool update) { var @in = new BufferedInputStream(rawin); var buffer = new byte[BlobImpl.CopybufferLength]; var bytesread = -1; while ((bytesread = rawin.Read(buffer)) >= 0) { sock.Write(buffer, 0, bytesread); if (update) { _currentByte += bytesread; } } @in.Close(); }
/// <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); }
/// <exception cref="System.IO.IOException"></exception> public abstract void ProcessClient(Socket4Adapter socket);
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> protected static StatefulBuffer ReadMessageBuffer(Transaction trans, Socket4Adapter socket) { return ReadMessageBuffer(trans, socket, Const4.MessageLength); }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> protected static StatefulBuffer ReadMessageBuffer(Db4objects.Db4o.Internal.Transaction trans, Socket4Adapter socket) { return(ReadMessageBuffer(trans, socket, Const4.MessageLength)); }
/// <exception cref="System.IO.IOException"></exception> public override void ProcessClient(Socket4Adapter sock) { }
/// <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); }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> protected static StatefulBuffer ReadMessageBuffer(Transaction trans, Socket4Adapter socket, int length) { var buffer = new StatefulBuffer(trans, length); var offset = 0; while (length > 0) { var read = socket.Read(buffer._buffer, offset, length); if (read < 0) { throw new Db4oIOException(); } offset += read; length -= read; } return buffer; }
internal override sealed Msg ReadPayLoad(IMessageDispatcher messageDispatcher, Transaction a_trans, Socket4Adapter sock, ByteArrayBuffer reader) { var length = reader.ReadInt(); a_trans = CheckParentTransaction(a_trans, reader); var command = (MsgD ) PublicClone(); command.SetTransaction(a_trans); command.SetMessageDispatcher(messageDispatcher); command._payLoad = ReadMessageBuffer(a_trans, sock, length); return command; }
private void AssertWriteClose(Socket4Adapter socketToBeClosed, ICodeBlock codeBlock ) { socketToBeClosed.Close(); Assert.Expect(typeof(Db4oIOException), new _ICodeBlock_102(codeBlock)); }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public static Msg ReadMessage(IMessageDispatcher messageDispatcher, Transaction trans, Socket4Adapter socket ) { var reader = ReadMessageBuffer(trans, socket); var message = _messages[reader.ReadInt()].ReadPayLoad (messageDispatcher, trans, socket, reader); return message; }
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; } } }
/// <param name="socket"></param> internal virtual Msg ReadPayLoad(IMessageDispatcher messageDispatcher, Transaction a_trans, Socket4Adapter socket, ByteArrayBuffer reader) { var msg = PublicClone(); msg.SetMessageDispatcher(messageDispatcher); msg.SetTransaction(CheckParentTransaction(a_trans, reader)); return msg; }