2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-11-24 01:36:54 +03:00
|
|
|
#include <stdio.h>
|
1999-05-04 04:31:40 +04:00
|
|
|
|
1999-05-04 22:50:59 +04:00
|
|
|
#ifdef WIN32
|
1999-04-19 11:17:37 +04:00
|
|
|
#include <windows.h>
|
1999-05-04 04:31:40 +04:00
|
|
|
#endif
|
2000-02-29 18:40:42 +03:00
|
|
|
#ifdef XP_OS2
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
1999-04-19 11:17:37 +04:00
|
|
|
|
|
|
|
#include "nscore.h"
|
1999-06-29 05:52:30 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-19 11:17:37 +04:00
|
|
|
#include "nsISocketTransportService.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2001-02-21 23:38:08 +03:00
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsIRequest.h"
|
1999-04-19 11:17:37 +04:00
|
|
|
#include "nsIStreamListener.h"
|
2000-08-22 11:03:33 +04:00
|
|
|
#include "nsIInputStream.h"
|
1999-04-19 11:17:37 +04: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...
|
2012-09-06 06:41:02 +04:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-04-19 11:17:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
InputTestConsumer::InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputTestConsumer::~InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-02 04:14:40 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(InputTestConsumer, nsIRequestObserver, nsIStreamListener)
|
1999-04-19 11:17:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
1999-04-19 11:17:37 +04:00
|
|
|
{
|
1999-07-01 23:30:20 +04:00
|
|
|
printf("+++ OnStartRequest +++\n");
|
1999-04-19 11:17:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
1999-07-07 12:08:40 +04:00
|
|
|
nsISupports* context,
|
1999-06-29 00:37:10 +04:00
|
|
|
nsIInputStream *aIStream,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t aSourceOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
1999-04-19 11:17:37 +04:00
|
|
|
{
|
|
|
|
char buf[1025];
|
|
|
|
while (aLength > 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t amt;
|
1999-07-13 06:37:08 +04:00
|
|
|
aIStream->Read(buf, 1024, &amt);
|
1999-09-10 02:05:05 +04:00
|
|
|
if (amt == 0) break;
|
1999-04-19 11:17:37 +04:00
|
|
|
buf[amt] = '\0';
|
|
|
|
printf(buf);
|
|
|
|
aLength -= amt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus)
|
1999-04-19 11:17:37 +04:00
|
|
|
{
|
|
|
|
gKeepRunning = 0;
|
1999-07-10 15:26:59 +04:00
|
|
|
printf("+++ OnStopRequest status %x +++\n", aStatus);
|
1999-04-19 11:17:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-06-08 16:24:10 +04:00
|
|
|
if (argc < 2) {
|
1999-04-19 11:17:37 +04: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 18:29:25 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
2002-07-04 18:29:25 +04:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
if (registrar)
|
2012-07-30 18:20:58 +04:00
|
|
|
registrar->AutoRegister(nullptr);
|
2002-07-04 18:29:25 +04:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = sts->CreateTransport(hostName, port, nullptr, 0, 0, &transport);
|
2002-07-04 18:29:25 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIRequest> request;
|
2012-07-30 18:20:58 +04:00
|
|
|
transport->AsyncRead(new InputTestConsumer, nullptr, 0, -1, 0, getter_AddRefs(request));
|
2002-07-04 18:29:25 +04:00
|
|
|
|
|
|
|
NS_RELEASE(transport);
|
|
|
|
}
|
1999-04-19 11:17:37 +04:00
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
// Enter the message pump to allow the URL load to proceed.
|
|
|
|
while ( gKeepRunning ) {
|
|
|
|
PLEvent *gEvent;
|
2003-04-04 20:01:51 +04:00
|
|
|
eventQ->WaitForEvent(&gEvent);
|
|
|
|
eventQ->HandleEvent(gEvent);
|
2002-07-04 18:29:25 +04:00
|
|
|
}
|
1999-11-02 00:57:14 +03:00
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_ShutdownXPCOM(nullptr);
|
2002-07-04 18:29:25 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
1999-04-19 11:17:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1999-06-22 22:24:02 +04:00
|
|
|
|