示例#1
0
文件: tcp_client.c 项目: devansc/464
int get_pkt(int socket) {
    int message_len = 0;     //length of the received message
    char *buf;              //buffer for receiving from client
    int buffer_size= MAX_PKT_LEN;  //packet size variable
    struct nrml_hdr pkt;

    //create packet buffer
    buf = (char *) malloc(buffer_size);
    memset(buf, 0, buffer_size);
    //now get the data on the socket
    if ((message_len = recv(socket, buf, buffer_size, 0)) < 0)
    {
        perror("recv call");
        exit(-1);
    } else if (message_len == 0) {   // server exitted
        close(socket);
        printf("Server Terminated\n");
        free(buf);
        return socket;     
    }
    
    memcpy(&pkt, buf, 7);
    switch (pkt.flag) {
    case INIT_ACK:
        break;
    case INIT_ACK_ERR: 
        printf("Handle already in use: %s\n", handle);
        exit(1);
    case BRDCST_MSG: 
        get_broadcast_message(buf, socket);
        break;
    case REG_MSG:
        get_message(buf + NRML_HDR_LEN, socket);
        break;
    case MSG_ACK:
        break;
    case MSG_ACK_ERR:
        printf("Client with handle %s does not exist.\n", get_handle_name(buf + NRML_HDR_LEN + 1, (uint8_t)*(buf + NRML_HDR_LEN)));
        break;
    case EXIT_ACK:
        close(socket);
        free(buf);
        return socket;;
    case HNDL_NUM:
        memcpy(&knownHandles, buf + NRML_HDR_LEN, 4);
        knownHandles = ntohl(knownHandles);
        break;
    case HNDL_PKT:
        recieve_handle_packet((uint8_t *) (buf + NRML_HDR_LEN), message_len - NRML_HDR_LEN);
        break;
    default:
        printf("Unkown flag %hhu\n", (uint8_t)(ntohs(pkt.flag) >> 8));
        break;
    }

    free(buf);
    return 0;
}
示例#2
0
文件: tcp_client.c 项目: devansc/464
void get_message(char *pkt, int client_socket) {
    uint8_t *toHandleLen, *fromHandleLen;
    char *msg;
    //char *toHandle, *fromHandle;

    toHandleLen = (uint8_t *)pkt;
    fromHandleLen = (uint8_t *)(pkt + 1 + *toHandleLen);
    msg = pkt + *toHandleLen + *fromHandleLen + 2;
    //printf("toHandleLen %u fromHandleLen %u\n", *toHandleLen, *fromHandleLen);
    printf("\n%s: %s\n", get_handle_name(pkt + *toHandleLen + 2, *fromHandleLen), msg);
}
示例#3
0
/**
 * Import an ANativeWindowBuffer allocated by the server.
 */
static struct pipe_resource *
import_buffer(struct android_display *adpy, const struct pipe_resource *templ,
              ANativeWindowBuffer *abuf)
{
   struct pipe_screen *screen = adpy->base.screen;
   struct pipe_resource *res;

   if (templ->bind & PIPE_BIND_RENDER_TARGET) {
      if (!screen->is_format_supported(screen, templ->format,
               templ->target, 0, PIPE_BIND_RENDER_TARGET))
         LOGW("importing unsupported buffer as render target");
   }
   if (templ->bind & PIPE_BIND_SAMPLER_VIEW) {
      if (!screen->is_format_supported(screen, templ->format,
               templ->target, 0, PIPE_BIND_SAMPLER_VIEW))
         LOGW("importing unsupported buffer as sampler view");
   }

   if (adpy->use_drm) {
      struct winsys_handle handle;

      memset(&handle, 0, sizeof(handle));
      handle.type = DRM_API_HANDLE_TYPE_SHARED;
      /* for DRM, we need the GEM name */
      handle.handle = get_handle_name(abuf->handle);
      if (!handle.handle) {
         LOGE("unable to import invalid buffer %p", abuf);
         return NULL;
      }

      handle.stride =
         abuf->stride * util_format_get_blocksize(templ->format);

      res = screen->resource_from_handle(screen, templ, &handle);
   }
   else {
      struct android_winsys_handle handle;

      memset(&handle, 0, sizeof(handle));
      handle.handle = abuf->handle;
      handle.stride =
         abuf->stride * util_format_get_blocksize(templ->format);

      res = screen->resource_from_handle(screen,
            templ, (struct winsys_handle *) &handle);
   }

   if (!res)
      LOGE("failed to import buffer %p", abuf);

   return res;
}
示例#4
0
文件: tcp_client.c 项目: devansc/464
void get_broadcast_message(char *pktStart, int client_socket) {
    uint8_t *fromHandleLen;
    char *msg;
    char *fromHandle;
    //int handle_socket, ndxHandle;
    char *pkt = pktStart + NRML_HDR_LEN;

    fromHandleLen = (uint8_t *)pkt;
    msg = strdup(pkt + *fromHandleLen + 1);
    //printf("toHandleLen %u fromHandleLen %u\n", *toHandleLen, *fromHandleLen);
    fromHandle = get_handle_name(pkt +1, *fromHandleLen);
    printf("\n%s: %s\n", fromHandle, msg);
}
示例#5
0
void windows_read_enter(CPUState *cpu, target_ulong pc, uint32_t FileHandle, uint32_t Event, uint32_t UserApcRoutine, uint32_t UserApcContext, uint32_t IoStatusBlock, uint32_t Buffer, uint32_t BufferLength, uint32_t ByteOffset, uint32_t Key) {
    int64_t offset = -1;
    if (ByteOffset != 0) {
        // Byte offset into file is specified (pointer to LARGE_INTEGER). Read and interpret.
        panda_virtual_memory_rw(cpu, ByteOffset, (uint8_t *)&offset, sizeof(offset), 0);
        //printf("NtReadFile: %lu[%ld]\n", (unsigned long)FileHandle, offset);
    } else {
        //printf("NtReadFile: %lu[]\n", (unsigned long)FileHandle);
    }

    char *filename = get_handle_name(cpu, get_current_proc(cpu), FileHandle);
    if (ByteOffset && (offset >= 0 && offset < (1L << 48))) {
        read_enter(cpu, pc, filename, offset, Buffer, BufferLength);
    }
    else {
        offset = get_file_handle_pos(cpu, get_current_proc(cpu), FileHandle);
        if (offset != -1)
            read_enter(cpu, pc, filename, offset, Buffer, BufferLength);
        else // last resort. just assume last_pos.
            read_enter(cpu, pc, filename, last_pos, Buffer, BufferLength);
    }
}
示例#6
0
static struct pipe_resource *
android_surface_add_cache(struct native_surface *nsurf,
                          ANativeWindowBuffer *abuf)
{
   struct android_surface *asurf = android_surface(nsurf);
   void *handle;
   int idx;

   /* how about abuf->usage? */
   if (asurf->cache_key.width != abuf->width ||
       asurf->cache_key.height != abuf->height ||
       asurf->cache_key.format != abuf->format)
      android_surface_clear_cache(&asurf->base);

   if (asurf->adpy->use_drm)
      handle = (void *) get_handle_name(abuf->handle);
   else
      handle = (void *) abuf->handle;
   /* NULL is invalid */
   if (!handle) {
      LOGE("invalid buffer native buffer %p", abuf);
      return NULL;
   }

   /* find the slot to use */
   for (idx = 0; idx < Elements(asurf->cache_handles); idx++) {
      if (asurf->cache_handles[idx] == handle || !asurf->cache_handles[idx])
         break;
   }
   if (idx == Elements(asurf->cache_handles)) {
      LOGW("cache full: buf %p, width %d, height %d, format %d, usage 0x%x",
            abuf, abuf->width, abuf->height, abuf->format, abuf->usage);
      android_surface_clear_cache(&asurf->base);
      idx = 0;
   }

   if (idx == 0) {
      asurf->cache_key.width = abuf->width;
      asurf->cache_key.height = abuf->height;
      asurf->cache_key.format = abuf->format;
   }

   if (!asurf->cache_handles[idx]) {
      struct pipe_resource templ;

      assert(!asurf->cache_resources[idx]);

      memset(&templ, 0, sizeof(templ));
      templ.target = PIPE_TEXTURE_2D;
      templ.format = get_pipe_format(asurf->buf->format);
      templ.bind = PIPE_BIND_RENDER_TARGET;
      if (!asurf->adpy->use_drm) {
         templ.bind |= PIPE_BIND_TRANSFER_WRITE |
                       PIPE_BIND_TRANSFER_READ;
      }

      templ.width0 = asurf->buf->width;
      templ.height0 = asurf->buf->height;
      templ.depth0 = 1;
      templ.array_size = 1;

      if (templ.format != PIPE_FORMAT_NONE) {
         asurf->cache_resources[idx] =
            import_buffer(asurf->adpy, &templ, asurf->buf);
      }
      else {
         asurf->cache_resources[idx] = NULL;
      }

      asurf->cache_handles[idx] = handle;
   }

   return asurf->cache_resources[idx];
}