Esempio n. 1
0
DWORD WINAPI listen_thread(void * d){
	MyServerSocket *that = (MyServerSocket *)d;
	sockaddr_in client;
	int size = sizeof(client);
	while (1){
		ZeroMemory(&client, size);
		if (that->status == socket_ready){
			int handle = ::accept(that->_socketHandle,(sockaddr*) &client, &size);
			if (handle < 0){
				int err = WSAGetLastError();
				if (err == WSAEWOULDBLOCK){
					Sleep(2000);
				}
				else{
					that->status = socket_err;
					break;
				}
				
			}
			else{
				that->onAccept(&client, handle);
			}
			Sleep(100);
		}
		else{
			break;
		}
	}
	that->status = socket_err;
	return NULL;
}
Esempio n. 2
0
/*
        bundle->setUrl( Amarok::QStringx("http://%1:3689/databases/%2/items/%3.%4?%5").args(
            QStringList() << m_host
                        << m_databaseId
                        << QString::number( (*it).asMap()["miid"].asList()[0].asInt() )
                        << (*it).asMap()["asfm"].asList()[0].asString()
                        << m_loginString ) );

*/
Proxy::Proxy(KURL stream, DaapClient* client, const char* name)
    : QObject(client, name)
    , m_proxy( new Amarok::ProcIO() )
{
    DEBUG_BLOCK
    //find the request id and increment it
    const QString hostKey = stream.host() + ':' + QString::number(stream.port());
    const int revisionId = client->incRevision( hostKey );
    const int sessionId = client->getSession( hostKey );
    //compose URL
    KURL realStream = realStreamUrl( stream, sessionId );

    //get hash
    char hash[33] = {0};
    GenerateHash( 3
        , reinterpret_cast<const unsigned char*>((realStream.path() + realStream.query()).ascii())
        , 2
        , reinterpret_cast<unsigned char*>(hash)
        , revisionId );

    // Find free port
    MyServerSocket* socket = new MyServerSocket();
    const int port = socket->port();
    debug() << "Proxy server using port: " << port << endl;
    delete socket;
    m_proxyUrl = KURL( QString("http://localhost:%1/daap.mp3").arg( port ) );
    //start proxy
    m_proxy->setComm( KProcess::Communication( KProcess::AllOutput ) );
    *m_proxy << "amarok_proxy.rb";
    *m_proxy << "--daap";
    *m_proxy << QString::number( port );
    *m_proxy << realStream.url();
    *m_proxy << AmarokConfig::soundSystem();
    *m_proxy << hash;
    *m_proxy << QString::number( revisionId );
    *m_proxy << Amarok::proxyForUrl( realStream.url() );

    if( !m_proxy->start( KProcIO::NotifyOnExit, true ) ) {
        error() << "Failed to start amarok_proxy.rb" << endl;
        return;
    }

    QString line;
    while( true ) {
        kapp->processEvents();
        m_proxy->readln( line );
        if( line == "AMAROK_PROXY: startup" ) break;
    }
    debug() << "started amarok_proxy.rb --daap " << QString::number( port ) << ' ' << realStream.url() << ' ' << AmarokConfig::soundSystem() << ' ' << hash << ' ' << revisionId << endl;
    connect( m_proxy, SIGNAL( processExited( KProcess* ) ), this, SLOT( playbackStopped() ) );
    connect( m_proxy, SIGNAL( readReady( KProcIO* ) ), this, SLOT( readProxy() ) );
}
Esempio n. 3
0
int main(int /*argc*/, char */*argv*/[]) {

  signal(SIGPIPE, SIG_IGN);

  MyServerSocket *server = new MyServerSocket(PORT);
  MySocket *client;

  pthread_t tid;
  while(true) {
    client = server->accept();
    pthread_create(&tid, NULL, child, client);
    pthread_detach(tid);
  }
}
Esempio n. 4
0
int main()
{
	SocketModule theSocket;

	MyServerSocket server;
	InputWatcher watcher(server);
	watcher.start();

	server.listen(IP(INADDR_ANY, 65432));
	server.accept();

	watcher.join();

	return 0;
}