Exemple #1
0
void FD_ConnectTask(FileDownload *fd)
{
    if (!fd->sock) {
        fd->num_connect_retry = 40;
        fd->sock = NewSocket(SK_TYPE_TCP);
    }

    /*connect*/
    fd->plug->error = M4OK;
    fd->plug->net_status = DL_WaitingForAck;
    fd->plug->OnState(fd->plug);

    fd->plug->error = SK_Connect(fd->sock, fd->server_name, fd->session_port);
    if (fd->plug->error == M4SockWouldBlock) {
        /*retry*/
        if (fd->num_connect_retry) {
            fd->num_connect_retry--;
            fd->plug->error = M4OK;
            return;
        }
    }

    /*failed*/
    if (fd->plug->error) {
        fd->plug->net_status = DL_Unavailable;
        FD_PostError(fd);
    } else {
        fd->plug->net_status = DL_Connected;
        fd->plug->OnState(fd->plug);
        SK_SetBlockingMode(fd->sock, 1);

        fd->use_cache = 0;
        if (!fd->disable_cache) FD_ConfigureCache(fd);
    }
}
Socket Socket_get_instance(){
	static Socket sock =NULL;
	if(sock==NULL){
		sock=NewSocket();
	}
	return sock;
}
Exemple #3
0
void Socket::Accept(SocketHolder *newSocket, bool nonBlocking,
                    sockaddr *newAddr, socklen_t *newAddrSize)
{
    if (!newSocket)
        throw SocketException("Invalid input parameter");
    if (newSocket->IsValid())
        throw SocketException("Input holder must be not initialized");
    SocketHolder NewSocket(accept4(GetHandle(), newAddr, newAddrSize, nonBlocking ? SOCK_NONBLOCK : 0));
    newSocket->Swap(NewSocket);
}
Exemple #4
0
	int Platform::ServerSocket()
	{
		int sfd;
		int error;
		int flags = 1;
		struct sockaddr_in sin;
		sin.sin_family = AF_INET;
		sin.sin_addr.s_addr = 0;
		sin.sin_port = htons(Settings::port);

		if((sfd = NewSocket()) == -1)
		{
			return -1;
		}

		//TODO: judge the return value
		setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&flags, sizeof(flags));
		setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, (void*)&flags, sizeof(flags));
		setsockopt(sfd, SOL_SOCKET, SO_LINGER, (void*)&flags, sizeof(flags));
		setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (void*)&flags, sizeof(flags));

		if(bind(sfd, (struct sockaddr*)&sin, sizeof(sin)) < 0)
		{
			perror("bind");
			close(sfd);
			return -1;
		}
		
		if(listen(sfd, Settings::backlog) < 0)
		{
			perror("listen");
			close(sfd);
			return -1;
		}

		return sfd;
	}
/**
Starts the sequence of operations that creates the platform specific objects,
registers the socket, and initialises the stack.

The function is called in the Variant DLL's entry point code, i.e. when
the kernel extension is initialised.

Note that the Variant DLL is a kernel extension.

@return KErrNone if creation and initialisation is successful;
        one of the other system wide error codes otherwise.
        
@see TMMCardControllerInterface::NewStack()
@see TMMCardControllerInterface::NewMediaChange()
@see TMMCardControllerInterface::NewVcc()
@see TMMCardControllerInterface::Init()
@see TMMCardControllerInterface::IsMMCStack()
@see TMMCardControllerInterface::MediaChangeID()
@see TMMCardControllerInterface::VccID()
*/	 
EXPORT_C TInt TMMCardControllerInterface::Create()
//
// Allocate any resources. Only done once on kernel initialization so don't
// worry about cleanup if it fails.
//
	{
	TInt r=KErrNone;
	__KTRACE_OPT(KPBUS1,Kern::Printf(">TMMCardControllerInterface::Create"));

	// Create the password store (a single password store
	//  is allocated for the use of all MMC stacks

	TMMCPasswordStore* theMmcPasswordStore = (TMMCPasswordStore*)LocDrv::PasswordStore();
	if(theMmcPasswordStore == NULL)
		{
		theMmcPasswordStore = new TMMCPasswordStore();
		if(theMmcPasswordStore)
			{
			if((r = theMmcPasswordStore->Init()) == KErrNone)
				r = LocDrv::RegisterPasswordStore(theMmcPasswordStore);					

			if(r != KErrNone)
				delete theMmcPasswordStore;
			}
		else
			{
			r = KErrNoMemory;
			}
		}

	if(r!= KErrNone)
		return r;

	r = Init();
	if (r != KErrNone)
		return r;


	SMediaDeviceInfo mdi;
	TInt i;
	for (i=0; i<KMaxPBusSockets && r==KErrNone; i++)
		{
		if (IsMMCSocket(i,mdi))
			{
			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d is MMC card",i));

			// Allocate a new socket
			DMMCSocket* pS = NewSocket(i, theMmcPasswordStore);
			if (!pS)
				{
				r=KErrNoMemory;
				break;
				}
			TheSockets[i]=pS;

			// Allocate a variant specific stack object via the interface
			DMMCStack* pStack=NewStack(i, pS);
			if (!pStack)
				{
				r=KErrNoMemory;
				break;
				}

			pS->iStack=pStack;

			TInt mcid=MediaChangeID(i);
			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Media Change %d",i,mcid));
			DMMCMediaChange* pM=(DMMCMediaChange*)TheMediaChanges[mcid];
			if (!pM)
				{
				__KTRACE_OPT(KPBUS1,Kern::Printf("New Media Change"));
				pM=NewMediaChange(mcid);
				if (!pM)
					{
					r=KErrNoMemory;
					break;
					}
				TheMediaChanges[mcid]=pM;
				__KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d at %08x",mcid,pM));
				r=pM->Create();
				if (r!=KErrNone)
					break;
				}
			else
				{
				__KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d already exists at %08x",mcid,pM));
				++pM->iReplyCount;
				}
			TInt vcc=VccID(i);
			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Vcc %d",i,vcc));
			DMMCPsu* pV=(DMMCPsu*)TheVccs[vcc];
			if (!pV)
				{
				__KTRACE_OPT(KPBUS1,Kern::Printf("New Vcc"));
				pV=NewVcc(vcc,mcid);
				if (!pV)
					{
					r=KErrNoMemory;
					break;
					}
				TheVccs[vcc]=pV;
				
				// Assign Socket here such that iDFc can be obtained
				pV->iSocket=pS;
				
				__KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d at %08x",vcc,pV));
				r=pV->Create();
				if (r!=KErrNone)
					break;
				}
			else 
				{
				__KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d already exists at %08x, mcid=%d",vcc,pV,pV->iMediaChangeNum));
// DISALLOW SHARED PSUs UNTIL SOMEONE NEEDS THEM
//				if (pV->iMediaChangeNum!=mcid)
//					{
					r=KErrInUse;
//					break;
//					}
				}
			
			DMMCPsu* pVCore=(DMMCPsu*)TheVccCores[vcc];
			// N.B. Assume paired vcc & vccQ unit are numbered identically!
			pVCore=NewVccCore(vcc,mcid);
			if (pVCore)
				{
				TheVccCores[vcc]=pVCore;
				__KTRACE_OPT(KPBUS1,Kern::Printf("VccCore %d at %08x",vcc,pVCore));
				
				// Assign Socket here such that iDFcQ can be obtained
				pVCore->iSocket=pS;
				
				r=pVCore->Create();
				if (r!=KErrNone)
					break;
				
				// VccCore must issue sleep instead of power down 
				pVCore->iPwrDownCheckFn = DMMCPsu::SleepCheck;				
				}
			//else do nothing doesn't matter if its not supported
			
			r=pS->Create(mdi.iDeviceName);
			if (r!=KErrNone)
				break;

			pS->iMediaChangeNumber=mcid;
			pS->iMediaChange=pM;
			pS->iVcc=pV;
			if (pVCore)
				{
				pS->iVccCore = pVCore;
				}

			r=pS->Init();
			if (r!=KErrNone)		
				break;

			r = RegisterMediaDevices(i);
			if(r != KErrNone)
			   break;
			
			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Created OK",i));
			}
		else
			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d not MMC card",i));
		}
		
	__KTRACE_OPT(KPBUS1,Kern::Printf("<TMMCardControllerInterface::Create, ret %d",r));
	return r;
	}