Changeset 749
- Timestamp:
- 12/6/2008 8:44:58 AM (4 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Manager/RemoteExecutor.cs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Manager/RemoteExecutor.cs
r748 r749 100 100 101 101 /// <summary> 102 /// Our pipe instance which handles connections.103 /// </summary>104 private NamedPipeServerStream server;105 106 /// <summary>107 102 /// Constructor. 108 103 /// </summary> 109 104 public RemoteExecutorServer() 110 105 { 111 server = new NamedPipeServerStream(ServerName, PipeDirection.InOut, 4,112 PipeTransmissionMode.Byte, PipeOptions.Asynchronous);113 114 106 thread = new Thread(Main); 115 107 thread.Start(); … … 131 123 { 132 124 //Wait for a connection to be established 133 if (!server.IsConnected) 134 { 135 IAsyncResult asyncWait = server.BeginWaitForConnection( 136 EndWaitForConnection, null); 137 while (!server.IsConnected && !asyncWait.AsyncWaitHandle.WaitOne(15)) 138 if (Thread.CurrentThread.ThreadState == ThreadState.AbortRequested) 139 break; 140 } 141 142 //If we still aren't connected that means the connection failed to establish. 143 if (!server.IsConnected) 144 continue; 145 125 NamedPipeServerStream server = new NamedPipeServerStream(ServerName, 126 PipeDirection.InOut, 4, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); 127 IAsyncResult asyncWait = server.BeginWaitForConnection( 128 EndWaitForConnection, server); 129 130 while (!server.IsConnected && !asyncWait.AsyncWaitHandle.WaitOne(15)) 131 if (Thread.CurrentThread.ThreadState == ThreadState.AbortRequested) 132 break; 133 134 //Execute the handler if the server was connected. 135 if (server.IsConnected) 136 ThreadPool.QueueUserWorkItem(ProcessConnection, server); 137 } 138 } 139 140 /// <summary> 141 /// Waits for a connection from a client. 142 /// </summary> 143 /// <param name="result">The AsyncResult object associated with this asynchronous 144 /// operation.</param> 145 private void EndWaitForConnection(IAsyncResult result) 146 { 147 NamedPipeServerStream server = (NamedPipeServerStream)result.AsyncState; 148 server.WaitForConnection(); 149 if (server.IsConnected) 150 server.EndWaitForConnection(result); 151 } 152 153 /// <summary> 154 /// Handles a new connection from the client. 155 /// </summary> 156 /// <param name="param">The connected NamedPipeServerStream instance.</param> 157 private void ProcessConnection(object param) 158 { 159 //Get the Server instance. 160 using (NamedPipeServerStream server = (NamedPipeServerStream)param) 161 { 146 162 //Read the request into the buffer. 147 163 RemoteRequest request = null; … … 160 176 //Ignore the request if the client disconnected from us. 161 177 if (!server.IsConnected) 162 continue;178 return; 163 179 164 180 //Deserialise the header of the request. … … 172 188 { 173 189 //We got a unserialisation issue but we can't do anything about it. 174 continue;190 return; 175 191 } 176 192 } … … 242 258 // void \+ ref task 243 259 case RemoteRequest.Function.ADD_TASK: 244 {245 Task task = (Task)parameter;246 AddTask(ref task);247 break;248 }260 { 261 Task task = (Task)parameter; 262 AddTask(ref task); 263 break; 264 } 249 265 250 266 // bool \+ taskid … … 298 314 server.Write(buffer, 0, sizeof(int)); 299 315 } 300 301 //We are done, disconnect302 server.Disconnect();303 316 } 304 }305 306 /// <summary>307 /// Waits for a connection from a client.308 /// </summary>309 /// <param name="result">The AsyncResult object associated with this asynchronous310 /// operation.</param>311 private void EndWaitForConnection(IAsyncResult result)312 {313 server.WaitForConnection();314 if (server.IsConnected)315 server.EndWaitForConnection(result);316 317 } 317 318 }
Note: See TracChangeset
for help on using the changeset viewer.
