1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
22
| Mono.ASPNET.BaseRequestBroker
25
| Gonzalo Paniagua Javier (gonzalo@ximian.com)
26
| Lluis Sanchez Gual (lluis@ximian.com)
28
|***************************************************************************/
32
using System.Collections;
36
public class BaseRequestBroker: MarshalByRefObject, IRequestBroker
38
ArrayList requests = new ArrayList ();
39
Queue freeSlots = new Queue ();
41
internal int RegisterRequest (IWorker worker)
45
if (freeSlots.Count == 0)
46
return requests.Add (worker);
48
int freeSlot = (int)freeSlots.Dequeue ();
49
requests [freeSlot] = worker;
54
internal void UnregisterRequest (int id)
59
freeSlots.Enqueue (id);
63
public int Read (int requestId, int size, out byte[] buffer)
65
buffer = new byte[size];
68
w = (IWorker) requests [requestId];
70
int nread = w.Read (buffer, 0, size);
74
public IWorker GetWorker (int requestId)
77
return (IWorker) requests [requestId];
81
public void Write (int requestId, byte[] buffer, int position, int size)
83
GetWorker (requestId).Write (buffer, position, size);
86
public void Close (int requestId)
88
GetWorker (requestId).Close ();
91
public void Flush (int requestId)
93
GetWorker (requestId).Flush ();
96
public override object InitializeLifetimeService ()