internal StateHttpWorkerRequest(IntPtr tracker, UnsafeNativeMethods.StateProtocolVerb methodIndex, string uri, UnsafeNativeMethods.StateProtocolExclusive exclusive, int extraFlags, int timeout, int lockCookieExists, int lockCookie, int contentLength, IntPtr content) { this._tracker = tracker; this._methodIndex = methodIndex; switch (this._methodIndex) { case UnsafeNativeMethods.StateProtocolVerb.GET: this._method = "GET"; break; case UnsafeNativeMethods.StateProtocolVerb.PUT: this._method = "PUT"; break; case UnsafeNativeMethods.StateProtocolVerb.DELETE: this._method = "DELETE"; break; case UnsafeNativeMethods.StateProtocolVerb.HEAD: this._method = "HEAD"; break; } this._uri = uri; if (this._uri.StartsWith("//", StringComparison.Ordinal)) { this._uri = this._uri.Substring(1); } this._exclusive = exclusive; this._extraFlags = extraFlags; this._timeout = timeout; this._lockCookie = lockCookie; this._lockCookieExists = lockCookieExists != 0; this._contentLength = contentLength; if (contentLength != 0) { uint num = (uint)((int)content); this._content = new byte[] { (byte)(num & 0xff), (byte)((num & 0xff00) >> 8), (byte)((num & 0xff0000) >> 0x10), (byte)((num & -16777216) >> 0x18) }; } this._status = new StringBuilder(0x100); this._headers = new StringBuilder(0x100); }
internal StateHttpWorkerRequest(IntPtr tracker, UnsafeNativeMethods.StateProtocolVerb methodIndex, string uri, UnsafeNativeMethods.StateProtocolExclusive exclusive, int extraFlags, int timeout, int lockCookieExists, int lockCookie, int contentLength, IntPtr content) { this._tracker = tracker; this._methodIndex = methodIndex; switch (this._methodIndex) { case UnsafeNativeMethods.StateProtocolVerb.GET: this._method = "GET"; break; case UnsafeNativeMethods.StateProtocolVerb.PUT: this._method = "PUT"; break; case UnsafeNativeMethods.StateProtocolVerb.DELETE: this._method = "DELETE"; break; case UnsafeNativeMethods.StateProtocolVerb.HEAD: this._method = "HEAD"; break; } this._uri = uri; if (this._uri.StartsWith("//", StringComparison.Ordinal)) { this._uri = this._uri.Substring(1); } this._exclusive = exclusive; this._extraFlags = extraFlags; this._timeout = timeout; this._lockCookie = lockCookie; this._lockCookieExists = lockCookieExists != 0; this._contentLength = contentLength; if (contentLength != 0) { uint num = (uint) ((int) content); this._content = new byte[] { (byte) (num & 0xff), (byte) ((num & 0xff00) >> 8), (byte) ((num & 0xff0000) >> 0x10), (byte) ((num & -16777216) >> 0x18) }; } this._status = new StringBuilder(0x100); this._headers = new StringBuilder(0x100); }
void MakeRequest( UnsafeNativeMethods.StateProtocolVerb verb, String id, UnsafeNativeMethods.StateProtocolExclusive exclusiveAccess, int extraFlags, int timeout, int lockCookie, byte[] buf, int cb, int networkTimeout, out UnsafeNativeMethods.SessionNDMakeRequestResults results) { int hr; string uri; OutOfProcConnection conn = null; HandleRef socketHandle; bool checkVersion = false; Debug.Assert(timeout <= SessionStateModule.MAX_CACHE_BASED_TIMEOUT_MINUTES, "item.Timeout <= SessionStateModule.MAX_CACHE_BASED_TIMEOUT_MINUTES"); SessionIDManager.CheckIdLength(id, true /* throwOnFail */); if (_partitionInfo == null) { Debug.Assert(s_partitionManager != null); Debug.Assert(_partitionResolver != null); _partitionInfo = (StateServerPartitionInfo)s_partitionManager.GetPartition(_partitionResolver, id); // If its still null, we give up if (_partitionInfo == null) { throw new HttpException(SR.GetString(SR.Bad_partition_resolver_connection_string, "PartitionManager")); } } // Need to make sure we dispose the connection if anything goes wrong try { conn = (OutOfProcConnection)_partitionInfo.RetrieveResource(); if (conn != null) { socketHandle = new HandleRef(this, conn._socketHandle.Handle); } else { socketHandle = new HandleRef(this, INVALID_SOCKET); } if (_partitionInfo.StateServerVersion == -1) { // We don't need locking here because it's okay to have two // requests initializing s_stateServerVersion. checkVersion = true; } Debug.Trace("OutOfProcSessionStateStoreMakeRequest", "Calling MakeRequest, " + "socket=" + (IntPtr)socketHandle.Handle + "verb=" + verb + " id=" + id + " exclusiveAccess=" + exclusiveAccess + " timeout=" + timeout + " buf=" + ((buf != null) ? "non-null" : "null") + " cb=" + cb + " checkVersion=" + checkVersion + " extraFlags=" + extraFlags); // Have to UrlEncode id because it may contain non-URL-safe characters uri = HttpUtility.UrlEncode(s_uribase + id); hr = UnsafeNativeMethods.SessionNDMakeRequest( socketHandle, _partitionInfo.Server, _partitionInfo.Port, _partitionInfo.ServerIsIPv6NumericAddress /* forceIPv6 */, networkTimeout, verb, uri, exclusiveAccess, extraFlags, timeout, lockCookie, buf, cb, checkVersion, out results); Debug.Trace("OutOfProcSessionStateStoreMakeRequest", "MakeRequest returned: " + "hr=" + hr + " socket=" + (IntPtr)results.socket + " httpstatus=" + results.httpStatus + " timeout=" + results.timeout + " contentlength=" + results.contentLength + " uri=" + (IntPtr)results.content + " lockCookie=" + results.lockCookie + " lockDate=" + string.Format("{0:x}", results.lockDate) + " lockAge=" + results.lockAge + " stateServerMajVer=" + results.stateServerMajVer + " actionFlags=" + results.actionFlags); if (conn != null) { if (results.socket == INVALID_SOCKET) { conn.Detach(); conn = null; } else if (results.socket != socketHandle.Handle) { // The original socket is no good. We've got a new one. // Pleae note that EnsureConnected has closed the bad // one already. conn._socketHandle = new HandleRef(this, results.socket); } } else if (results.socket != INVALID_SOCKET) { conn = new OutOfProcConnection(results.socket); } if (conn != null) { _partitionInfo.StoreResource(conn); } } catch { // We just need to dispose the connection if anything bad happened if (conn != null) { conn.Dispose(); } throw; } if (hr != 0) { HttpException e = CreateConnectionException(_partitionInfo.Server, _partitionInfo.Port, hr); string phase = null; switch (results.lastPhase) { case (int)UnsafeNativeMethods.SessionNDMakeRequestPhase.Initialization: phase = SR.GetString(SR.State_Server_detailed_error_phase0); break; case (int)UnsafeNativeMethods.SessionNDMakeRequestPhase.Connecting: phase = SR.GetString(SR.State_Server_detailed_error_phase1); break; case (int)UnsafeNativeMethods.SessionNDMakeRequestPhase.SendingRequest: phase = SR.GetString(SR.State_Server_detailed_error_phase2); break; case (int)UnsafeNativeMethods.SessionNDMakeRequestPhase.ReadingResponse: phase = SR.GetString(SR.State_Server_detailed_error_phase3); break; default: Debug.Assert(false, "Unknown results.lastPhase: " + results.lastPhase); break; } WebBaseEvent.RaiseSystemEvent(SR.GetString(SR.State_Server_detailed_error, phase, "0x" + hr.ToString("X08", CultureInfo.InvariantCulture), cb.ToString(CultureInfo.InvariantCulture)), this, WebEventCodes.WebErrorOtherError, WebEventCodes.StateServerConnectionError, e); throw e; } if (results.httpStatus == 400) { if (s_usePartition) { throw new HttpException( SR.GetString(SR.Bad_state_server_request_partition_resolver, s_configPartitionResolverType, _partitionInfo.Server, _partitionInfo.Port.ToString(CultureInfo.InvariantCulture))); } else { throw new HttpException( SR.GetString(SR.Bad_state_server_request)); } } if (checkVersion) { _partitionInfo.StateServerVersion = results.stateServerMajVer; if (_partitionInfo.StateServerVersion < WHIDBEY_MAJOR_VERSION) { // We won't work with versions lower than Whidbey if (s_usePartition) { throw new HttpException( SR.GetString(SR.Need_v2_State_Server_partition_resolver, s_configPartitionResolverType, _partitionInfo.Server, _partitionInfo.Port.ToString(CultureInfo.InvariantCulture))); } else { throw new HttpException( SR.GetString(SR.Need_v2_State_Server)); } } } }
internal StateHttpWorkerRequest( IntPtr tracker, UnsafeNativeMethods.StateProtocolVerb methodIndex, string uri, UnsafeNativeMethods.StateProtocolExclusive exclusive, int extraFlags, int timeout, int lockCookieExists, int lockCookie, int contentLength, IntPtr content ) { _tracker = tracker; _methodIndex = methodIndex; switch (_methodIndex) { case UnsafeNativeMethods.StateProtocolVerb.GET: _method = "GET"; break; case UnsafeNativeMethods.StateProtocolVerb.PUT: _method = "PUT"; break; case UnsafeNativeMethods.StateProtocolVerb.HEAD: _method = "HEAD"; break; case UnsafeNativeMethods.StateProtocolVerb.DELETE: _method = "DELETE"; break; default: Debug.Assert(false, "Shouldn't get here!"); break; } _uri = uri; // Handle the ASP1.1 case which prepends an extra / to the URI if (_uri.StartsWith("//", StringComparison.Ordinal)) { _uri = _uri.Substring(1); } _exclusive = exclusive; _extraFlags = extraFlags; _timeout = timeout; _lockCookie = lockCookie; _lockCookieExists = lockCookieExists != 0; _contentLength = contentLength; if (contentLength != 0) { Debug.Assert(_contentLength == IntPtr.Size); // Need to convert 'content', which is a ptr to native StateItem, // into a byte array because that's what GetPreloadedEntityBody // must return, and GetPreloadedEntityBody is what the pipeline uses // to read the body of the request, which in our case is just a pointer // to a native StateItem object. #if WIN64 ulong p = (ulong) content; _content = new byte[8] { (byte) ((p & 0x00000000000000ff)), (byte) ((p & 0x000000000000ff00) >> 8), (byte) ((p & 0x0000000000ff0000) >> 16), (byte) ((p & 0x00000000ff000000) >> 24), (byte) ((p & 0x000000ff00000000) >> 32), (byte) ((p & 0x0000ff0000000000) >> 40), (byte) ((p & 0x00ff000000000000) >> 48), (byte) ((p & 0xff00000000000000) >> 56), }; #else uint p = (uint) content; _content = new byte[4] { (byte) ((p & 0x000000ff)), (byte) ((p & 0x0000ff00) >> 8), (byte) ((p & 0x00ff0000) >> 16), (byte) ((p & 0xff000000) >> 24), }; #endif } _status = new StringBuilder(256); _headers = new StringBuilder(256); }
internal StateHttpWorkerRequest( IntPtr tracker, UnsafeNativeMethods.StateProtocolVerb methodIndex, string uri, UnsafeNativeMethods.StateProtocolExclusive exclusive, int timeout, int lockCookieExists, int lockCookie, int contentLength, IntPtr content ) { _tracker = tracker; _methodIndex = methodIndex; switch (_methodIndex) { case UnsafeNativeMethods.StateProtocolVerb.GET: _method = "GET"; break; case UnsafeNativeMethods.StateProtocolVerb.PUT: _method = "PUT"; break; case UnsafeNativeMethods.StateProtocolVerb.HEAD: _method = "HEAD"; break; case UnsafeNativeMethods.StateProtocolVerb.DELETE: _method = "DELETE"; break; default: Debug.Assert(false, "Shouldn't get here!"); break; } _uri = uri; _exclusive = exclusive; _timeout = timeout; _lockCookie = lockCookie; _lockCookieExists = lockCookieExists != 0; _contentLength = contentLength; if (contentLength != 0) { Debug.Assert(_contentLength == IntPtr.Size); if (IntPtr.Size == 4) { uint p = (uint)content; _content = new byte[4] { (byte)((p & 0x000000ff)), (byte)((p & 0x0000ff00) >> 8), (byte)((p & 0x00ff0000) >> 16), (byte)((p & 0xff000000) >> 24), }; } else { ulong p = (ulong)content; _content = new byte[8] { (byte)((p & 0x00000000000000ff)), (byte)((p & 0x000000000000ff00) >> 8), (byte)((p & 0x0000000000ff0000) >> 16), (byte)((p & 0x00000000ff000000) >> 24), (byte)((p & 0x000000ff00000000) >> 32), (byte)((p & 0x0000ff0000000000) >> 40), (byte)((p & 0x00ff000000000000) >> 48), (byte)((p & 0xff00000000000000) >> 56), }; } } _status = new StringBuilder(256); _headers = new StringBuilder(256); }
internal StateHttpWorkerRequest( IntPtr tracker, UnsafeNativeMethods.StateProtocolVerb methodIndex, string uri, UnsafeNativeMethods.StateProtocolExclusive exclusive, int extraFlags, int timeout, int lockCookieExists, int lockCookie, int contentLength, IntPtr content ) { _tracker = tracker; _methodIndex = methodIndex; switch (_methodIndex) { case UnsafeNativeMethods.StateProtocolVerb.GET: _method = "GET"; break; case UnsafeNativeMethods.StateProtocolVerb.PUT: _method = "PUT"; break; case UnsafeNativeMethods.StateProtocolVerb.HEAD: _method = "HEAD"; break; case UnsafeNativeMethods.StateProtocolVerb.DELETE: _method = "DELETE"; break; default: Debug.Assert(false, "Shouldn't get here!"); break; } _uri = uri; // Handle the ASP1.1 case which prepends an extra / to the URI if (_uri.StartsWith("//", StringComparison.Ordinal)) { _uri = _uri.Substring(1); } _exclusive = exclusive; _extraFlags = extraFlags; _timeout = timeout; _lockCookie = lockCookie; _lockCookieExists = lockCookieExists != 0; _contentLength = contentLength; if (contentLength != 0) { Debug.Assert(_contentLength == IntPtr.Size); // Need to convert 'content', which is a ptr to native StateItem, // into a byte array because that's what GetPreloadedEntityBody // must return, and GetPreloadedEntityBody is what the pipeline uses // to read the body of the request, which in our case is just a pointer // to a native StateItem object. #if WIN64 ulong p = (ulong)content; _content = new byte[8] { (byte)((p & 0x00000000000000ff)), (byte)((p & 0x000000000000ff00) >> 8), (byte)((p & 0x0000000000ff0000) >> 16), (byte)((p & 0x00000000ff000000) >> 24), (byte)((p & 0x000000ff00000000) >> 32), (byte)((p & 0x0000ff0000000000) >> 40), (byte)((p & 0x00ff000000000000) >> 48), (byte)((p & 0xff00000000000000) >> 56), }; #else uint p = (uint)content; _content = new byte[4] { (byte)((p & 0x000000ff)), (byte)((p & 0x0000ff00) >> 8), (byte)((p & 0x00ff0000) >> 16), (byte)((p & 0xff000000) >> 24), }; #endif } _status = new StringBuilder(256); _headers = new StringBuilder(256); }
void MakeRequest( UnsafeNativeMethods.StateProtocolVerb verb, String id, UnsafeNativeMethods.StateProtocolExclusive exclusiveAccess, int timeout, int lockCookie, byte[] buf, int cb, int networkTimeout, out UnsafeNativeMethods.SessionNDMakeRequestResults results) { int hr; string uri; OutOfProcConnection conn; HandleRef socketHandle; conn = (OutOfProcConnection)s_rpool.RetrieveResource(); if (conn != null) { socketHandle = new HandleRef(this, conn._socketHandle.Handle); } else { socketHandle = new HandleRef(this, INVALID_SOCKET); } Debug.Trace("SessionStateClientManagerMakeRequest", "Calling MakeRequest, " + "socket=" + (IntPtr)socketHandle.Handle + "verb=" + verb + " id=" + id + " exclusiveAccess=" + exclusiveAccess + " timeout=" + timeout + " buf=" + ((buf != null) ? "non-null" : "null") + " cb=" + cb); uri = s_uribase + id; hr = UnsafeNativeMethods.SessionNDMakeRequest( socketHandle, s_server, s_port, networkTimeout, verb, uri, exclusiveAccess, timeout, lockCookie, buf, cb, out results); Debug.Trace("SessionStateClientManagerMakeRequest", "MakeRequest returned: " + "hr=" + hr + " socket=" + (IntPtr)results.socket + " httpstatus=" + results.httpStatus + " timeout=" + results.timeout + " contentlength=" + results.contentLength + " uri=" + (IntPtr)results.content + " lockCookie=" + results.lockCookie + " lockDate=" + string.Format("{0:x}", results.lockDate) + " lockAge=" + results.lockAge); if (conn != null) { if (results.socket == INVALID_SOCKET) { conn.Detach(); conn = null; } else if (results.socket != socketHandle.Handle) { // The original socket is no good. We've got a new one. // Pleae note that EnsureConnected has closed the bad // one already. conn._socketHandle = new HandleRef(this, results.socket); } } else if (results.socket != INVALID_SOCKET) { conn = new OutOfProcConnection(results.socket); } if (conn != null) { s_rpool.StoreResource(conn); } if (hr != 0) { throw new HttpException( HttpRuntime.FormatResourceString(SR.Cant_make_session_request), hr); } }