Exemplo n.º 1
0
/*static*/ SysStatus
FileLinuxPacket::CreateInternal(FileLinuxRef& newSocket, ObjectHandle stubOH,
				uval clientType, uval oflags, sval domain,
			        sval type, sval protocol)
{
    SysStatus rc;
    FileLinuxPacket *newp = NULL;

    ObjectHandle dummy;

    switch (type) {
    case SOCK_DGRAM:
    case SOCK_RAW:
	switch (domain) {
	case AF_NETLINK:
	case AF_INET:
	    newp = new FileLinuxPacket(domain, type, protocol);
	    break;
	case AF_UNIX:
	    newp = (FileLinuxPacket*) new FileLinuxPacketUnix(domain, type,
                                                        protocol);
	    break;
	default:
	    tassertMsg(0, "fixme.  Add the domain (%ld) here as well.\n",
	                 domain);
	    break;
	}
	break;
    default:
	tassertMsg(0, "fixme.  Add the type (%ld) here as well.\n", type);
	break;
    }

    // using dummy tells init not to make a stubHolder
    dummy.init();
    newp->init(dummy, NULL);

    newp->local = newp->remote = 0;
    newp->localLen = newp->remoteLen = 0;

    newp->sps.setOH(stubOH);

    switch (clientType) {
    case TransStreamServer::TRANS_VIRT:
	newp->stubHolder = new TransVirtStream(stubOH);
	break;
    case TransStreamServer::TRANS_PPC:
	newp->stubHolder = new TransPPCStream(stubOH);
	break;
    default:
	err_printf("Unknown socket client type: %ld\n", clientType);
    }

    newSocket = (FileLinuxRef)newp->getRef();

    // register object for callback by server
    rc = newp->registerCallback();
    tassert(_SUCCESS(rc), err_printf("do cleanup code\n"));
    return 0;
}
Exemplo n.º 2
0
int
__k42_linux_msgrcv(int msqid, struct msgbuf *msgp,
                   int msgsz, sval msgtyp, int msgflg)
{
    int ret;
    SysStatus rc;
    ObjectHandle oh;
    void *blockKey;
    BlockedThreadQueues::Element qe;

    SYSCALL_ENTER();

    if (msgflg&IPC_NOWAIT) {
	oh.init();
    } else {
	SysVMessagesClient::GetCallBackOH(oh, blockKey);
	DREFGOBJ(TheBlockedThreadQueuesRef)->
	    addCurThreadToQueue(&qe, blockKey);
    }
	
    while (1) {
	rc = StubSysVMessages::Msgrcv(msqid, msgtyp, msgp->mtext,
				      msgsz, msgflg, oh);

	if (_FAILURE(rc)) {
	    ret = -_SGENCD(rc);
	} else {
	    ret = (int)_SGETUVAL(rc);
	}
	if ((ret == -ENOMSG) & !(msgflg&IPC_NOWAIT)) {
	    SYSCALL_BLOCK();
	    if (SYSCALL_SIGNALS_PENDING()) {
		// need to do removeCur.. on the way out, so don't just return
		ret = -EINTR;
		break;
	    }
	} else break;
    }

    if(!(msgflg&IPC_NOWAIT)) {
	DREFGOBJ(TheBlockedThreadQueuesRef)->
	    removeCurThreadFromQueue(&qe, blockKey);
    }

    SYSCALL_EXIT();
    return ret;
}
Exemplo n.º 3
0
Arquivo: smtTest.C Projeto: jimix/k42
int
main(int argc, char *argv[])
{
    NativeProcess();

    const char *optlet = "acA";
    int c;
    int server=0;
    int alloc_test=0;
    while ((c = getopt(argc, argv, optlet)) != EOF) {
	switch (c) {
	    case 'c':
		server=0;
		break;
	    case 'a':
		server=1;
		break;
	    case 'A':
		alloc_test =1;
		break;
	}
    }

    ProcessID pid = DREFGOBJ(TheProcessRef)->getPID();
    if (server) {
	printf("Pid is:%ld\n",pid);
	startupSecondaryProcessors();
	MetaObj::init();
	MetaMemTrans::init();
	ObjectHandle fake;
	XHandle partner;
	MemTransRef mtr;
	fake.init();

	MTHandlerSrv mts(Scheduler::GetCurThread());

	SysStatus rc = MemTrans::Create(mtr, fake, 64*PAGE_SIZE, partner, &mts);
	printf("MemTrans::Create: %016ld\n",rc);

	if (alloc_test) {

#define A(spot,count) (((spot)<<12) | (count))
#define D(spot,count) ((1<<11) | ((spot)<<12) | (count))
	    uval sequence[15] = { A(0,9), A(1,9), A(2,9), A(3,9), A(4,9),
				  A(5,9), A(6,9),
				  D(1,9), D(3,9), D(2,9),
				  A(1,25), A(2,1), A(3,1),0};

	    void *allocs[8]={NULL,};
	    uval slot = 0;
	    while (sequence[slot]!=0) {

		uval spot = (sequence[slot] & ~((1<<12) - 1))>>12;
		uval count= sequence[slot] & ((1<<11) - 1);
		if ( sequence[slot] & 1<<11 ) {
		    DREF(mtr)->freePagePtr(allocs[spot]);
		    printf("Free: %ld %p %ld\n",spot,allocs[spot],count);
		} else {
		    uval addr;
		    DREF(mtr)->allocPagesLocal(addr, count);
		    allocs[slot]=(void*)addr;
		    printf("Alloc: %ld %p %ld\n",spot,allocs[slot],count);
		}

		++slot;
	    }
	}
	mts.waitForNext();
	printf("Received connection: %016lx\n",mts.other);

	mts.waitForNext();
	printf("Received ring: %016lx %ld\n",mts.other,mts.ring);

	for (uval i=0; i<1001; ++i) {
	    while (1) {
		rc = DREF(mtr)->insertToRing(mts.ring, i);
		if (_FAILURE(rc)) {
		    printf("insert failure: %016lx\n",rc);
		    mts.waitForNext();
		} else {
		    break;
		}
	    }
	}
    } else {