예제 #1
0
파일: text.c 프로젝트: ChenZewei/acoral
static void
GetChnFontData(
    char* pBuffer,
    FONT* pFont,
    char* pChar
)
{
    unsigned char qh,wh;
    int iOffset;
    //qu-wei code of chinese
    qh=*(pChar)-0xa0;
    wh=*(pChar+1)-0xa0;
    if(qh>=0x10) {
        iOffset=pFont->iOffset + pFont->FontLibHeader.iSize
                + pFont->FontLibHeader.iChnOffset;
        iOffset=iOffset
                + ((94*(qh-1)+(wh-1))-0x0582)* pFont->FontLibHeader.iChnBytes;
    }
    else {
        iOffset=pFont->iOffset + pFont->FontLibHeader.iSize
                + pFont->FontLibHeader.iChnSymOffset;
        iOffset=iOffset
                + (94*(qh-1)+(wh-1)) * pFont->FontLibHeader.iChnBytes;
    }
    shm_read(pBuffer, iOffset, pFont->FontLibHeader.iChnBytes);
}
예제 #2
0
int main()
{
    int choice = 1;

    shmget(2009, SHMSIZE, 0666 | IPC_CREAT);

    while (1) {
        printf("1 Parent writes\n"
                "2 Parent reads\n"
                "3 Child writes\n"
                "4 Child reads\n"
                "5 quit\n");
        scanf("%d", &choice);
        switch(choice) {
            case 1:
                shm_write("Parent");
                break;
            case 2:
                shm_read("Parent");
                break;
            case 3:
                if (fork() == 0) {
                    shm_write("Child");
                }
                else {
                    wait(NULL);
                    break;
                }
            case 4:
                if (fork() == 0) {
                    shm_read("Child");
                }
                else {
                    wait(NULL);
                }
                break;
            default:
                exit(0);
        }
    }
    shmctl(shmid, IPC_RMID, NULL);
    return 0;
}
예제 #3
0
파일: text.c 프로젝트: ChenZewei/acoral
static void
GetAscFontData(
    char* pBuffer,
    FONT* pFont,
    char* pChar
)
{
    int iOffset;
    iOffset=pFont->iOffset + pFont->FontLibHeader.iSize
            + pFont->FontLibHeader.iAscOffset;
    iOffset=iOffset+(*pChar) * pFont->FontLibHeader.iAscBytes;
    shm_read(pBuffer, iOffset, pFont->FontLibHeader.iAscBytes);
}
예제 #4
0
파일: ZmqEnd.cpp 프로젝트: europelee/pigeon
    void ZmqEnd::backThreadFunc() {
        LOG(INFO)<<"backThreadFunc start";

        mBackSock.connect(mInProcUri);

        while(!mThreadInter) {
            /* wait*/
            int wRet = mBinSem.timeWait(3);
            if (wRet == -1) {
                if (errno != ETIMEDOUT)
                    LOG(ERROR)<<strerror(errno);
                continue;
            }
            /*get msg from queue*/
            repInfo * ptRepO = nullptr;
            int ret = shm_read(&mCommCtlInfo, (void *)&ptRepO, sizeof(void *), STREAM_IN_DIRECT);
            if (SHM_OPT_FAIL == ret)
            {
                LOG(ERROR)<<"shm_read fail";
                continue;
            }
            /*send msg with zmq*/
            int cliIdSize = strlen(ptRepO->mPtrCliId);
            int payloadSize = strlen(ptRepO->mPtrPayLoad);
            zmq::message_t outCliIdMsg(cliIdSize);
            memcpy ((void *)outCliIdMsg.data(), ptRepO->mPtrCliId, cliIdSize);
            mBackSock.send(outCliIdMsg, ZMQ_SNDMORE);

            zmq::message_t outPayloadMsg(payloadSize);
            memcpy((void *)outPayloadMsg.data(), ptRepO->mPtrPayLoad, payloadSize);
            mBackSock.send(outPayloadMsg, 0);

            releaseRepInfoObj(&ptRepO);
            ptRepO = nullptr;
        }

        LOG(INFO)<<"backThreadFunc end";    
    }
예제 #5
0
파일: test3_1.c 프로젝트: areinull/shmci
int main(void)
{
    const char *path1="/usr/include/stdio.h";
    const int ch1='A';
    const char *path2="/usr/include/stdio.h";
    const int ch2='B';
    const char *path3="/usr/include/stdio.h";
    const int ch3='C';
    char *text3="\nThis is the test text #3 and integer: ";
    char text1[256],text2[256];
    ShmLink link1,link2,link3;
    int size1,size2,err,i=0,res1=0,res2=0;

    size1=strlen(text3)+1;
    size2=sizeof(int);

    if( (err=shm_connect(&link3,path3,ch3,size1+size2))<0 )
    {
        fprintf(stderr,"[%s:%d] Error #%d for shm_link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link3));
        return -1;
    }
    sleep(1);
    if( (err=shm_connect(&link2,path2,ch2,size1+size2))<0 )
    {
        fprintf(stderr,"[%s:%d] Error #%d for shm_link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link2));
        return -1;
    }
    if( (err=shm_connect(&link1,path1,ch1,size1+size2))<0 )
    {
        fprintf(stderr,"[%s:%d] Error #%d for shm_link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link1));
        return -1;
    }
    for(i=0;i<10;i++)
    {
        if( (err=shm_write(&link3,text3,0,size1))<0 )
        {
            fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link3));
            return -2;
        }
        if( (err=shm_write(&link3,&i,size1,size2))<0 )
        {
            fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link3));
            return -2;
        }

        if( (err=shm_read(&link1,text1,0,size1))<0 )
        {
            fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link1));
            return -2;
        }
        if( (err=shm_read(&link1,&res1,size1,size2))<0 )
        {
            fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link1));
            return -2;
        }
        if( (err=shm_read(&link2,text2,0,size1))<0 )
        {
            fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link2));
            return -2;
        }
        if( (err=shm_read(&link2,&res2,size1,size2))<0 )
        {
            fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link2));
            return -2;
        }
        sleep(2);
    }
    if( (err=shm_disconnect(&link1))<0 )
    {
        fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link1));
        return -4;
    }
    if( (err=shm_disconnect(&link2))<0 )
    {
        fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link2));
        return -4;
    }
    if( (err=shm_disconnect(&link3))<0 )
    {
        fprintf(stderr,"[%s:%d] Error #%d for link:\n%s",
                __FILE__,__LINE__,err,shm_strerror(&link3));
        return -4;
    }

    return 0;
}
예제 #6
0
파일: shcon.c 프로젝트: rbong/shcon
int shcon_recv_shm_msg (shcon_t* _shcon, msg_t** _msg, int _init)
{
    int tmp = 0;
    int ret = 0;
    int _offset = 0;

    if (_shcon == NULL || _shcon->shm == NULL)
    {
        ERR_PRINT (_EPTRNULL);
        ret = -1;
        return ret;
    }

    if (!(_shcon->locked))
    {
        // todo- new error
        ERR_PRINT (_EBADVAL);
        ret = -1;
        return ret;
    }

    (*_msg) = msg_t_new ();
    if (_msg == NULL || (*_msg) == NULL)
    {
        ERR_FROM ();
        ret = -1;
        return ret;
    }

    if (!_init)
    {
        tmp = msg_to_raw_len (&shcon_msg_init);
        if (tmp < 0)
        {
            ERR_FROM ();
            msg_t_del (_msg);
            ret = -1;
            return ret;
        }
        _offset += tmp;
    }
    tmp = shm_read
            (_shcon->shm, &((*_msg)->type), sizeof (enum _MSG_TYPE), _offset);
    if (tmp < 0)
    {
        ERR_FROM ();
        msg_t_del (_msg);
        ret = -1;
        return ret;
    }
    _offset += sizeof ((*_msg)->type);
    tmp = shm_read
            (_shcon->shm, &((*_msg)->hdr), sizeof (msg_hdr_t), _offset);
    if (tmp < 0)
    {
        ERR_FROM ();
        msg_t_del (_msg);
        ret = -1;
        return ret;
    }
    if ((*_msg)->hdr.len != 0)
    {
        (*_msg)->data = malloc ((*_msg)->hdr.len);
        if ((*_msg)->data == NULL)
        {
            ERR_PRINT (_EALLOC);
            ret = -1;
            return ret;
        }

        _offset += sizeof ((*_msg)->hdr);
        tmp = shm_read
            (_shcon->shm, (*_msg)->data, (*_msg)->hdr.len, _offset);
        if (tmp < 0)
        {
            ERR_FROM ();
            msg_t_del (_msg);
            ret = -1;
            return ret;
        }
    }

    tmp = _shcon_check_prev_time (_shcon, (*_msg));
    ret = tmp;
    if (tmp < 0)
    {
        ERR_FROM ();
        return ret;
    }

    if (tmp)
    {
        tmp = _shcon_set_prev_time (_shcon, (*_msg));
        if (tmp < 0)
        {
            ERR_FROM ();
            ret = tmp;
        }
    }
    return ret;
}