static void
handle_image_load(int wfd, void *params)
{
   Slave_Msg_Image_Load *load_args = params;
   Slave_Msg_Image_Loaded resp;
   Error_Type err;
   const char *shmfile;
   const char *file, *key, *loader;

   if (!load_args->has_loader_data)
     {
        error_send(wfd, CSERVE2_UNKNOWN_FORMAT);
        return;
     }

   memset(&resp, 0, sizeof(resp));

   shmfile = ((const char *)params) + sizeof(Slave_Msg_Image_Load);
   file = shmfile + strlen(shmfile) + 1;
   key = file + strlen(file) + 1;
   loader = key + strlen(key) + 1;
   if ((err = image_load(file, key, shmfile, load_args, &resp, loader))
       != CSERVE2_NONE)
     {
        error_send(wfd, err);
        return;
     }

   response_send(wfd, IMAGE_LOAD, &resp, sizeof(resp));
}
예제 #2
0
int main(int c, char **v)
{
   int wfd, rfd;
   Slave_Command cmd;
   void *params = NULL;
   Eina_Module *m;
   Eina_Bool quit = EINA_FALSE;

   if (c < 3)
     return 1;

   eina_init();
   pfx =  eina_prefix_new(v[0], main,
                          "EVAS", "evas", "checkme",
                          PACKAGE_BIN_DIR,
                          PACKAGE_LIB_DIR,
                          PACKAGE_DATA_DIR,
                          PACKAGE_DATA_DIR);

   loaders = eina_hash_string_superfast_new(NULL);
   evas_module_init();

   wfd = atoi(v[1]);
   rfd = atoi(v[2]);

   while (!quit)
     {
        if (!command_read(rfd, &cmd, &params))
          {
             error_send(wfd, CSERVE2_INVALID_COMMAND);
             return 1;
          }
        switch (cmd)
          {
           case IMAGE_OPEN:
             handle_image_open(wfd, params);
             break;
           case IMAGE_LOAD:
             handle_image_load(wfd, params);
             break;
           case SLAVE_QUIT:
             quit = EINA_TRUE;
             break;
           default:
             error_send(wfd, CSERVE2_INVALID_COMMAND);
          }
     }

   evas_module_shutdown();
   eina_hash_free(loaders);

   EINA_LIST_FREE(modules, m)
      eina_module_free(m);

   eina_prefix_free(pfx);
   eina_shutdown();

   return 0;
}
예제 #3
0
파일: clients.c 프로젝트: yurial/netio
void client_sendall(char* buff, const size_t buffsize)
{
int clientindex = 0;
int setindex = client2set( 0 );
while (clientindex < g_clients.m_count)
    {
    struct pollfd* set = g_set + setindex;
    struct TClient* client = g_clients.m_client + clientindex;

    int sendsize = send( client->m_sock, buff, buffsize, MSG_DONTWAIT );
    if ( sendsize == -1 )
        {
        if ( errno == EWOULDBLOCK )
            {
            sendsize = 0;
            }
        else
            {
            error_send( errno );
            client_disconnect( client );
            continue;
            }
        }
    if ( sendsize < buffsize )
        {
        ++g_clients.m_blocked;
        client->m_sendbuff = buff + sendsize;
        client->m_remain = buffsize - sendsize;
        set->events |= POLLOUT;
        }
    ++clientindex;
    ++setindex;
    }
}
예제 #4
0
static void
handle_image_open(int wfd, void *params)
{
   Slave_Msg_Image_Open *p;
   Slave_Msg_Image_Opened result;
   Error_Type err;
   const char *loader = NULL, *file, *key, *ptr;
   char *resp;
   size_t resp_size;

   p = params;
   file = (const char *)(p + sizeof(Slave_Msg_Image_Open));
   key = file + strlen(file) + 1;
   ptr = key + strlen(key) + 1;
   if (p->has_loader_data)
     loader = ptr;

   memset(&result, 0, sizeof(result));
   if ((err = image_open(file, key, &result, &loader))
       != CSERVE2_NONE)
     {
        printf("OPEN failed at %s:%d\n", __FUNCTION__, __LINE__);
        error_send(wfd, err);
        return;
     }

   result.has_loader_data = EINA_TRUE;

   resp_size = sizeof(Slave_Msg_Image_Opened) + sizeof(int) + strlen(loader) + 1;
   resp = alloca(resp_size);
   memcpy(resp, &result, sizeof(Slave_Msg_Image_Opened));
   memcpy(resp + sizeof(Slave_Msg_Image_Opened), loader, strlen(loader) + 1);
   response_send(wfd, IMAGE_OPEN, resp, resp_size);
}
예제 #5
0
파일: clients.c 프로젝트: yurial/netio
int client_POLLOUT(int nready, struct pollfd* set, struct TClient* client, char* recvbuff)
{
set->revents ^= POLLOUT;
--nready;

const int sock = client->m_sock;
const char* sendbuff = client->m_sendbuff;
const int remain = client->m_remain;

int sendsize = send( sock, sendbuff, remain, MSG_DONTWAIT | MSG_NOSIGNAL );
if ( sendsize == -1 )
    {
    assert( errno != EWOULDBLOCK ); //WTF?
    /* if error */
    error_send( errno );
    client_disconnect( client );
    return nready;
    }
if ( sendsize < remain )
    {
    /* if not all sended */
    client->m_sendbuff += sendsize;
    client->m_remain -= sendsize;
    }
else
    {
    /* if all sended */
    client->m_sendbuff = NULL;
    client->m_remain = 0;
    set->events &= ~POLLOUT;
    --g_clients.m_blocked;
    if ( g_set[STDIN_FILENO].fd == -1 ) //stdin closed
        {
        client_tdisconnect( client );
        }
    }
return nready;
}