public static void dumpStream(BasicStream stream) { int pos = stream.pos(); stream.pos(0); byte[] data = new byte[stream.size()]; stream.readBlob(data); dumpOctets(data); stream.pos(pos); }
internal static void traceRecv(BasicStream str, Ice.Logger logger, TraceLevels tl) { if(tl.protocol >= 1) { int p = str.pos(); str.pos(0); using(System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture)) { byte type = printMessage(s, str); logger.trace(tl.protocolCat, "received " + getMessageTypeAsString(type) + " " + s.ToString()); } str.pos(p); } }
internal static void trace(string heading, BasicStream str, Ice.Logger logger, TraceLevels tl) { if(tl.protocol >= 1) { int p = str.pos(); str.pos(0); using(System.IO.StringWriter s = new System.IO.StringWriter(CultureInfo.CurrentCulture)) { s.Write(heading); printMessage(s, str); logger.trace(tl.protocolCat, s.ToString()); } str.pos(p); } }
// // Writeable stream constructor // public StreamWrapper(BasicStream s) { type_ = StreamType.Write; s_ = s; spos_ = s.pos(); bytes_ = new byte[254]; pos_ = 0; length_ = 0; }
public void invoke(ServantManager servantManager, BasicStream stream) { _is = stream; int start = _is.pos(); // // Read the current. // current_.id.read__(_is); // // For compatibility with the old FacetPath. // string[] facetPath = _is.readStringSeq(); if(facetPath.Length > 0) { if(facetPath.Length > 1) { throw new Ice.MarshalException(); } current_.facet = facetPath[0]; } else { current_.facet = ""; } current_.operation = _is.readString(); current_.mode = (Ice.OperationMode)(int)_is.readByte(); current_.ctx = new Dictionary<string, string>(); int sz = _is.readSize(); while(sz-- > 0) { string first = _is.readString(); string second = _is.readString(); current_.ctx[first] = second; } Ice.Instrumentation.CommunicatorObserver obsv = instance_.initializationData().observer; if(obsv != null) { // Read the encapsulation size. int size = _is.readInt(); _is.pos(_is.pos() - 4); observer_ = obsv.getDispatchObserver(current_, _is.pos() - start + size); if(observer_ != null) { observer_.attach(); } } // // Don't put the code above into the try block below. Exceptions // in the code above are considered fatal, and must propagate to // the caller of this operation. // if(servantManager != null) { servant_ = servantManager.findServant(current_.id, current_.facet); if(servant_ == null) { locator_ = servantManager.findServantLocator(current_.id.category); if(locator_ == null && current_.id.category.Length > 0) { locator_ = servantManager.findServantLocator(""); } if(locator_ != null) { try { servant_ = locator_.locate(current_, out cookie_); } catch(Ice.UserException ex) { Ice.EncodingVersion encoding = _is.skipEncaps(); // Required for batch requests. if(observer_ != null) { observer_.userException(); } if(response_) { os_.writeByte(ReplyStatus.replyUserException); os_.startWriteEncaps(encoding, Ice.FormatType.DefaultFormat); os_.writeUserException(ex); os_.endWriteEncaps(); if(observer_ != null) { observer_.reply(os_.size() - Protocol.headerSize - 4); } responseHandler_.sendResponse(current_.requestId, os_, compress_, false); } else { responseHandler_.sendNoResponse(); } if(observer_ != null) { observer_.detach(); observer_ = null; } responseHandler_ = null; return; } catch(System.Exception ex) { _is.skipEncaps(); // Required for batch requests. handleException__(ex, false); return; } } } } try { if(servant_ != null) { // // DispatchAsync is a "pseudo dispatch status", used internally only // to indicate async dispatch. // if(servant_.dispatch__(this, current_) == Ice.DispatchStatus.DispatchAsync) { // // If this was an asynchronous dispatch, we're done here. // return; } if(locator_ != null && !servantLocatorFinished__(false)) { return; } } else { // // Skip the input parameters, this is required for reading // the next batch request if dispatching batch requests. // _is.skipEncaps(); if(servantManager != null && servantManager.hasServant(current_.id)) { throw new Ice.FacetNotExistException(current_.id, current_.facet, current_.operation); } else { throw new Ice.ObjectNotExistException(current_.id, current_.facet, current_.operation); } } } catch(System.Exception ex) { if(servant_ != null && locator_ != null && !servantLocatorFinished__(false)) { return; } handleException__(ex, false); return; } // // Don't put the code below into the try block above. Exceptions // in the code below are considered fatal, and must propagate to // the caller of this operation. // Debug.Assert(responseHandler_ != null); if(response_) { if(observer_ != null) { observer_.reply(os_.size() - Protocol.headerSize - 4); } responseHandler_.sendResponse(current_.requestId, os_, compress_, false); } else { responseHandler_.sendNoResponse(); } if(observer_ != null) { observer_.detach(); observer_ = null; } responseHandler_ = null; }
public void sendResponse(int requestId, BasicStream os, byte status, bool amd) { Ice.AsyncCallback cb = null; OutgoingAsyncBase outAsync; lock(this) { Debug.Assert(_response); os.pos(Protocol.replyHdr.Length + 4); if(_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); TraceUtil.traceRecv(os, _logger, _traceLevels); } if(_asyncRequests.TryGetValue(requestId, out outAsync)) { _asyncRequests.Remove(requestId); outAsync.getIs().swap(os); cb = outAsync.completed(); } } if(cb != null) { if(amd) { outAsync.invokeCompletedAsync(cb); } else { outAsync.invokeCompleted(cb); } } _adapter.decDirectCount(); }
private void invokeAll(BasicStream os, int requestId, int batchRequestNum) { if(batchRequestNum > 0) { os.pos(Protocol.requestBatchHdr.Length); } else { os.pos(Protocol.requestHdr.Length); } if(_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); if(requestId > 0) { fillInValue(os, Protocol.headerSize, requestId); } else if(batchRequestNum > 0) { fillInValue(os, Protocol.headerSize, batchRequestNum); } TraceUtil.traceSend(os, _logger, _traceLevels); } int invokeNum = batchRequestNum > 0 ? batchRequestNum : 1; ServantManager servantManager = _adapter.getServantManager(); try { while(invokeNum > 0) { // // Increase the direct count for the dispatch. We increase it again here for // each dispatch. It's important for the direct count to be > 0 until the last // collocated request response is sent to make sure the thread pool isn't // destroyed before. // try { _adapter.incDirectCount(); } catch(Ice.ObjectAdapterDeactivatedException ex) { handleException(requestId, ex, false); break; } Incoming @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0, requestId); @in.invoke(servantManager, os); --invokeNum; } } catch(Ice.LocalException ex) { invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception } _adapter.decDirectCount(); }
private void invokeAll(BasicStream os, int requestId, int invokeNum, bool batch) { if(batch) { os.pos(Protocol.requestBatchHdr.Length); } else { os.pos(Protocol.requestHdr.Length); } if(_traceLevels.protocol >= 1) { fillInValue(os, 10, os.size()); if(requestId > 0) { fillInValue(os, Protocol.headerSize, requestId); } else if(batch) { fillInValue(os, Protocol.headerSize, invokeNum); } TraceUtil.traceSend(os, _logger, _traceLevels); } ServantManager servantManager = _adapter.getServantManager(); try { while(invokeNum > 0) { try { _adapter.incDirectCount(); } catch(Ice.ObjectAdapterDeactivatedException ex) { handleException(requestId, ex, false); return; } Incoming @in = new Incoming(_reference.getInstance(), this, null, _adapter, _response, (byte)0, requestId); @in.invoke(servantManager, os); --invokeNum; } } catch(Ice.LocalException ex) { invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception } }
public bool compress(ref BasicStream cstream, int headerSize, int compressionLevel) { #if MANAGED || COMPACT cstream = this; return false; #else if(!_bzlibInstalled) { cstream = this; return false; } // // Compress the message body, but not the header. // int uncompressedLen = size() - headerSize; byte[] uncompressed = _buf.b.rawBytes(headerSize, uncompressedLen); int compressedLen = (int)(uncompressedLen * 1.01 + 600); byte[] compressed = new byte[compressedLen]; int rc = NativeMethods.BZ2_bzBuffToBuffCompress(compressed, ref compressedLen, uncompressed, uncompressedLen, compressionLevel, 0, 0); if(rc == BZ_OUTBUFF_FULL) { cstream = null; return false; } else if(rc < 0) { Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffCompress failed"); ex.reason = getBZ2Error(rc); throw ex; } // // Don't bother if the compressed data is larger than the // uncompressed data. // if(compressedLen >= uncompressedLen) { return false; } cstream = new BasicStream(instance_); cstream.resize(headerSize + 4 + compressedLen, false); cstream.pos(0); // // Copy the header from the uncompressed stream to the // compressed one. // cstream._buf.b.put(_buf.b.rawBytes(0, headerSize)); // // Add the size of the uncompressed stream before the // message body. // cstream.writeInt(size()); // // Add the compressed message body. // cstream._buf.b.put(compressed, 0, compressedLen); return true; #endif }
public BasicStream uncompress(int headerSize) { #if MANAGED || COMPACT return this; #else if(!_bzlibInstalled) { return this; } pos(headerSize); int uncompressedSize = readInt(); if(uncompressedSize <= headerSize) { throw new Ice.IllegalMessageSizeException("compressed size <= header size"); } int compressedLen = size() - headerSize - 4; byte[] compressed = _buf.b.rawBytes(headerSize + 4, compressedLen); int uncompressedLen = uncompressedSize - headerSize; byte[] uncompressed = new byte[uncompressedLen]; int rc = NativeMethods.BZ2_bzBuffToBuffDecompress(uncompressed, ref uncompressedLen, compressed, compressedLen, 0, 0); if(rc < 0) { Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffDecompress failed"); ex.reason = getBZ2Error(rc); throw ex; } BasicStream ucStream = new BasicStream(instance_); ucStream.resize(uncompressedSize, false); ucStream.pos(0); ucStream._buf.b.put(_buf.b.rawBytes(0, headerSize)); ucStream._buf.b.put(uncompressed, 0, uncompressedLen); return ucStream; #endif }