JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_read(JNIEnv * env, jclass clazz, jint fd, jobject jbuffer, jint pos, jint limit) {
    void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
    if (buffer == NULL) {
        throwRuntimeException(env, "Unable to access address of buffer");
        return -1;
    }
    return read0(env, clazz, fd, buffer, pos, limit);
}
Пример #2
0
void com_gw(int in)
{
    fd_set               fds;
    int                  n, fdsbits;
    static struct timeval    tout = { TIMEOUT, 0 };
    unsigned char buf[MBUFSIZ];
    
    alarm(0);
    
    fdsbits = in + 1;
    
    while (1)
    {
        FD_ZERO(&    fds);
        FD_SET (in, &fds);
        FD_SET (0 , &fds);
        FD_SET (1 , &fds);
	
        tout.tv_sec  = TIMEOUT;
        tout.tv_usec = 0;
        if ((n = select(fdsbits, &fds, NULL, NULL, &tout)) > 0)
	{
            if (FD_ISSET(in, &fds))
	    {
                if ((n = read(in, buf, sizeof buf)) > 0)
		{
                    if (write1(buf, n) < 0) goto bad;
                }
		else
		    goto bad;
            }
            if (FD_ISSET(0, &fds))
	    {
                if ((n = read0(buf, sizeof buf)) > 0)
		{
                    if (write(in, buf, n) < 0) goto bad;
                }
		else goto bad;
            }
        } 
        else goto bad;
    }
bad:    ;   
}
Пример #3
0
/* Get a command from the client.
 * If a command is received, returns 1,
 * otherwise return 0.
 */
int get_command(struct vtcmd *v)
{
  int i,loc;
  char ch,bootbuf[40];

  sum0 = 0;
  sum1 = 0;

  /* Get a valid command from the client */
  read0(portfd, &v->hdr1, 1);

  /* Send down the bootstrap code to ODT if we see an @ sign */
  if ((havesentbootcode==0) && (v->hdr1 == '@')) {
    writeC(ttyfd,&v->hdr1,1);
    for (i=0,loc=BOOTSTART;i<(sizeof(bootcode)/sizeof(int));i++,loc+=2) {
	sprintf(bootbuf, "%06o/", loc);
	writeP(portfd, bootbuf, strlen(bootbuf));

	/* wait for current value to print */
	while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch==' ') break; }
	sprintf(bootbuf, "%06o\r", bootcode[i]);
	writeP(portfd, bootbuf, strlen(bootbuf));

	/* and suck up any characters sent from ODT */
	while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch=='@') break; }
    }
    sprintf(bootbuf, "r6/", loc);
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch==' ') break; }
    sprintf(bootbuf, "%06o\r", BOOTSTACK);
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch=='@') break; }
    sprintf(bootbuf, "r7/", loc);
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch==' ') break; }
    sprintf(bootbuf, "%06o\r", BOOTSTART);
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch=='@') break; }
    sprintf(bootbuf, "rs/", loc);
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch==' ') break; }
    sprintf(bootbuf, "%06o\r", 000340);
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch=='@') break; }
    sprintf(bootbuf, "p");
    writeP(portfd, bootbuf, strlen(bootbuf));
    while (1) { readP(portfd, &ch, 1); writeC(ttyfd,&ch,1); if (ch=='p') break; }
    havesentbootcode=1; return(0);
  }

  if (v->hdr1 != VT_HDR1) { v->hdr1&= 127; writeC(1,&v->hdr1, 1); return(0); }
  read1(portfd, &v->hdr2, 1);
  if (v->hdr2 != VT_HDR2) { v->hdr1&= 127; writeC(1,&v->hdr1, 1); v->hdr2&= 127; writeC(1,&v->hdr2, 1); return(0); }

  read0(portfd, &v->cmd, 1); read1(portfd, &v->record, 1);
  read0(portfd, &v->blklo, 1); read1(portfd, &v->blkhi, 1);
  block = v->blkhi<<8&0xff00 | v->blklo&0xff;
  if(block>=0xff00)
	{
	unsigned char tmp0,tmp1;

	read0(portfd, &tmp0, 1);
	read1(portfd, &tmp1, 1);
	block = tmp1<<16&0xff0000 | tmp0<<8&0xff00 | v->blklo&0xff;
	}


  /* All done if a quick read */
  if (v->cmd == VTC_QUICK) return(1);

  /* Retrieve the block if a WRITE cmd */
  if (v->cmd == VTC_WRITE) {
    for (i = 0; i < BLKSIZE; i++) {
      read0(portfd, &inbuf[i], 1); i++;
      read1(portfd, &inbuf[i], 1);
    }
  }

  /* Get the checksum */
  read0(portfd, &(v->sum0), 1);
  read1(portfd, &(v->sum1), 1);

  /* Try again on a bad checksum */
  if (sum0 | sum1)
    { fputc('e',stderr); return(0); }

  return(1);
}
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_readAddress(JNIEnv * env, jclass clazz, jint fd, jlong address, jint pos, jint limit) {
    return read0(env, clazz, fd, (void*) address, pos, limit);
}