| 12 | | //* |
|---|
| 13 | | //* onSocketAccepted |
|---|
| 14 | | //* |
|---|
| 15 | | //* Called when the server socket accepts a new connection. This |
|---|
| 16 | | //* connection is passed to an nsITransport, included as a parameter. |
|---|
| 17 | | //* |
|---|
| 18 | | //* PARAMETERS: |
|---|
| 19 | | //* serverSocket: The socket which took the connection |
|---|
| 20 | | //* transport: The nsITransport generated by accepting the connection. |
|---|
| 21 | | //* |
|---|
| 22 | | onSocketAccepted : function(serverSocket, transport){ |
|---|
| | 12 | //* |
|---|
| | 13 | //* onSocketAccepted |
|---|
| | 14 | //* |
|---|
| | 15 | //* Called when the server socket accepts a new connection. This |
|---|
| | 16 | //* connection is passed to an nsITransport, included as a parameter. |
|---|
| | 17 | //* |
|---|
| | 18 | //* PARAMETERS: |
|---|
| | 19 | //* serverSocket: The socket which took the connection |
|---|
| | 20 | //* transport: The nsITransport generated by accepting the connection. |
|---|
| | 21 | //* |
|---|
| | 22 | onSocketAccepted : function(serverSocket, transport) { |
|---|
| 32 | | // Set up a pump to funnel input to a listener |
|---|
| 33 | | var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"]. |
|---|
| 34 | | createInstance(Components.interfaces.nsIInputStreamPump); |
|---|
| 35 | | pump.init(input, -1, -1, 0, 0, false); |
|---|
| 36 | | pump.asyncRead(dataListener,null); |
|---|
| | 32 | // Set up a pump to funnel input to a listener |
|---|
| | 33 | var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"]. |
|---|
| | 34 | createInstance(Components.interfaces.nsIInputStreamPump); |
|---|
| | 35 | pump.init(input, -1, -1, 0, 0, false); |
|---|
| | 36 | pump.asyncRead(dataListener,null); |
|---|
| 48 | | onStopRequest: function(request, context, status) { |
|---|
| 49 | | if(receivedData.substring(0,3) == "INFO"){ |
|---|
| 50 | | var ownChunkList = new Array(); |
|---|
| 51 | | var curChunk; |
|---|
| 52 | | for(curChunk = 0; curChunk < numChunk; curChunk++) { |
|---|
| 53 | | if(chunks_held[curChunk] != null) |
|---|
| 54 | | ownChunkList[curChunk] = true; |
|---|
| 55 | | else |
|---|
| 56 | | ownChunkList[curChunk] = false; |
|---|
| | 48 | onStopRequest: function(request, context, status) { |
|---|
| | 49 | if(receivedData.substring(0,3) == "INFO") { |
|---|
| | 50 | var ownChunkList = new Array(); |
|---|
| | 51 | var curChunk; |
|---|
| | 52 | for(curChunk = 0; curChunk < numChunk; curChunk++) { |
|---|
| | 53 | if(chunks_held[curChunk] != null) |
|---|
| | 54 | ownChunkList[curChunk] = true; |
|---|
| | 55 | else |
|---|
| | 56 | ownChunkList[curChunk] = false; |
|---|
| | 57 | } |
|---|
| | 58 | output.write(ownChunkList,ownChunkList.length); |
|---|
| 58 | | output.write(ownChunkList,ownChunkList.length); |
|---|
| 59 | | |
|---|
| 60 | | } |
|---|
| 61 | | else{ |
|---|
| 62 | | for(curChar;curChar<receivedData.length;curChar++){ |
|---|
| 63 | | if(receivedData.substring(curChar,curChar+5)=="CHUNK "){ |
|---|
| 64 | | var temp=receivedDataArray[receivedData.substring(curChar+6,curChar+6)]; |
|---|
| 65 | | output.write(temp,temp.length); |
|---|
| 66 | | break; |
|---|
| | 60 | else { |
|---|
| | 61 | for(curChar;curChar<receivedData.length;curChar++){ |
|---|
| | 62 | if(receivedData.substring(curChar,curChar+5)=="CHUNK "){ |
|---|
| | 63 | var temp=receivedDataArray[receivedData.substring(curChar+6,curChar+6)]; |
|---|
| | 64 | output.write(temp,temp.length); |
|---|
| | 65 | break; |
|---|
| | 66 | } |
|---|
| 69 | | } |
|---|
| 70 | | }, |
|---|
| 71 | | onDataAvailable: function(request, context, inputStream, offset, count) { |
|---|
| 72 | | var sinput = Components.classes["@mozilla.org/scriptableinputstream;1"] |
|---|
| 73 | | .createInstance(Components.interfaces.nsIScriptableInputStream); |
|---|
| 74 | | sinput.init(inputStream); |
|---|
| 75 | | receivedData+= sinput.read(count); |
|---|
| 76 | | } |
|---|
| 77 | | }; |
|---|
| 78 | | |
|---|
| 79 | | } |
|---|
| 80 | | } |
|---|
| 81 | | } |
|---|
| | 69 | }, |
|---|
| | 70 | |
|---|
| | 71 | |
|---|
| | 72 | onDataAvailable: function(request, context, inputStream, offset, count) { |
|---|
| | 73 | var sinput = Components.classes["@mozilla.org/scriptableinputstream;1"] |
|---|
| | 74 | .createInstance(Components.interfaces.nsIScriptableInputStream); |
|---|
| | 75 | sinput.init(inputStream); |
|---|
| | 76 | receivedData+= sinput.read(count); |
|---|
| | 77 | }, |
|---|
| | 78 | }; |
|---|
| | 79 | } // Closes onSocketAccepted |
|---|
| | 80 | } // Closes serverListener |
|---|
| | 81 | } // Closes overhaul_replyer |
|---|