2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-04-19 07:17:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-04-19 07:17:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-04-19 07:17:37 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-11-23 22:36:54 +00:00
|
|
|
#include <stdio.h>
|
1999-05-04 00:31:40 +00:00
|
|
|
|
1999-05-04 18:50:59 +00:00
|
|
|
#ifdef WIN32
|
1999-04-19 07:17:37 +00:00
|
|
|
#include <windows.h>
|
1999-05-04 00:31:40 +00:00
|
|
|
#endif
|
2000-02-29 15:40:42 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
1999-04-19 07:17:37 +00:00
|
|
|
|
|
|
|
#include "nscore.h"
|
1999-06-29 01:52:30 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-19 07:17:37 +00:00
|
|
|
#include "nsISocketTransportService.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2001-02-21 20:38:08 +00:00
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsIRequest.h"
|
1999-04-19 07:17:37 +00:00
|
|
|
#include "nsIStreamListener.h"
|
2000-08-22 07:03:33 +00:00
|
|
|
#include "nsIInputStream.h"
|
1999-04-19 07:17:37 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
|
|
|
|
|
|
|
static int gKeepRunning = 1;
|
|
|
|
|
|
|
|
class InputTestConsumer : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
InputTestConsumer();
|
|
|
|
virtual ~InputTestConsumer();
|
|
|
|
|
|
|
|
// ISupports interface...
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// IStreamListener interface...
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHOD OnStartRequest(nsIRequest *request, nsISupports* context);
|
1999-04-19 07:17:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHOD OnDataAvailable(nsIRequest *request, nsISupports* context,
|
1999-06-28 20:37:10 +00:00
|
|
|
nsIInputStream *aIStream,
|
1999-04-22 08:47:06 +00:00
|
|
|
PRUint32 aSourceOffset,
|
1999-04-19 07:17:37 +00:00
|
|
|
PRUint32 aLength);
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
NS_IMETHOD OnStopRequest(nsIRequest *request, nsISupports* context,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult aStatus);
|
1999-06-07 21:33:30 +00:00
|
|
|
|
1999-04-19 07:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
InputTestConsumer::InputTestConsumer()
|
|
|
|
{
|
2002-09-07 17:13:19 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
1999-04-19 07:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputTestConsumer::~InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-02 01:14:40 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(InputTestConsumer, nsIRequestObserver, nsIStreamListener)
|
1999-04-19 07:17:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
1999-04-19 07:17:37 +00:00
|
|
|
{
|
1999-07-01 19:30:20 +00:00
|
|
|
printf("+++ OnStartRequest +++\n");
|
1999-04-19 07:17:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsISupports* context,
|
1999-06-28 20:37:10 +00:00
|
|
|
nsIInputStream *aIStream,
|
1999-04-22 08:47:06 +00:00
|
|
|
PRUint32 aSourceOffset,
|
1999-04-19 07:17:37 +00:00
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
|
|
|
char buf[1025];
|
|
|
|
while (aLength > 0) {
|
|
|
|
PRUint32 amt;
|
1999-07-13 02:37:08 +00:00
|
|
|
aIStream->Read(buf, 1024, &amt);
|
1999-09-09 22:05:05 +00:00
|
|
|
if (amt == 0) break;
|
1999-04-19 07:17:37 +00:00
|
|
|
buf[amt] = '\0';
|
|
|
|
printf(buf);
|
|
|
|
aLength -= amt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult aStatus)
|
1999-04-19 07:17:37 +00:00
|
|
|
{
|
|
|
|
gKeepRunning = 0;
|
1999-07-10 11:26:59 +00:00
|
|
|
printf("+++ OnStopRequest status %x +++\n", aStatus);
|
1999-04-19 07:17:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-06-08 12:24:10 +00:00
|
|
|
if (argc < 2) {
|
1999-04-19 07:17:37 +00:00
|
|
|
printf("usage: %s <host>\n", argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int port;
|
|
|
|
char* hostName = argv[1];
|
|
|
|
//nsString portString(argv[2]);
|
|
|
|
|
|
|
|
//port = portString.ToInteger(&rv);
|
|
|
|
port = 13;
|
2002-07-04 14:29:25 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
|
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
if (registrar)
|
|
|
|
registrar->AutoRegister(nsnull);
|
|
|
|
|
|
|
|
// Create the Event Queue for this thread...
|
|
|
|
nsCOMPtr<nsIEventQueueService> eventQService =
|
|
|
|
do_GetService(kEventQueueServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEventQueue> eventQ;
|
|
|
|
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISocketTransportService> sts =
|
|
|
|
do_GetService(kSocketTransportServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsITransport* transport;
|
|
|
|
|
|
|
|
rv = sts->CreateTransport(hostName, port, nsnull, 0, 0, &transport);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIRequest> request;
|
2003-01-02 01:14:40 +00:00
|
|
|
transport->AsyncRead(new InputTestConsumer, nsnull, 0, -1, 0, getter_AddRefs(request));
|
2002-07-04 14:29:25 +00:00
|
|
|
|
|
|
|
NS_RELEASE(transport);
|
|
|
|
}
|
1999-04-19 07:17:37 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
// Enter the message pump to allow the URL load to proceed.
|
|
|
|
while ( gKeepRunning ) {
|
1999-05-04 18:50:59 +00:00
|
|
|
#ifdef WIN32
|
2002-07-04 14:29:25 +00:00
|
|
|
MSG msg;
|
1999-04-19 07:17:37 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
1999-06-03 18:34:51 +00:00
|
|
|
#else
|
|
|
|
#ifdef XP_MAC
|
2002-07-04 14:29:25 +00:00
|
|
|
/* Mac stuff is missing here! */
|
2000-02-29 15:40:42 +00:00
|
|
|
#else
|
|
|
|
#ifdef XP_OS2
|
2002-07-04 14:29:25 +00:00
|
|
|
QMSG qmsg;
|
2000-02-29 15:40:42 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
if (WinGetMsg(0, &qmsg, 0, 0, 0))
|
|
|
|
WinDispatchMsg(0, &qmsg);
|
|
|
|
else
|
|
|
|
gKeepRunning = FALSE;
|
1999-06-03 18:34:51 +00:00
|
|
|
#else
|
2002-07-04 14:29:25 +00:00
|
|
|
PLEvent *gEvent;
|
|
|
|
rv = eventQ->GetEvent(&gEvent);
|
|
|
|
rv = eventQ->HandleEvent(gEvent);
|
1999-06-03 18:34:51 +00:00
|
|
|
#endif
|
2000-02-29 15:40:42 +00:00
|
|
|
#endif
|
1999-04-19 07:17:37 +00:00
|
|
|
#endif
|
2002-07-04 14:29:25 +00:00
|
|
|
}
|
1999-11-01 21:57:14 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
|
|
|
rv = NS_ShutdownXPCOM(nsnull);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
1999-04-19 07:17:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-06-22 18:24:02 +00:00
|
|
|
|