예제 #1
0
파일: ACK.hpp 프로젝트: K099/ZhyCore
    void encode()
    {

        Packet::encode();
        buffer+=ID;
        std::vector<int>::iterator iter= needACK.begin();
        std::sort(iter,needACK.end());
        int count=needACK.size();
        int records=0;
        if(count>0)
        {
            //int pointer=1;
            int start = *iter;
            int last = *iter;

            while(iter != needACK.end())
            {
                iter++;
                int current=*iter;
                int diff=current-last;
                if(diff==1)
                {
                    last = current;
                }
                else if(diff>1)
                {
                    if(start==last)
                    {
                        payload+="\x01";
                        payload+=writeLTriad(start);
                        start=last=current;
                    }
                    else
                    {
                        payload+="\x00";
                        payload+=writeLTriad(start);
                        payload+=writeLTriad(last);
                        start=last=current;
                    }
                    ++records;
                }

            }
            if(start==last)
            {
                payload += "\x01";
                payload += writeLTriad(start);
            }
            else
            {
                payload += "\x00";
                payload += writeLTriad(start);
                payload += writeLTriad(last);
            }
            ++records;
        }
        putShort(records);

        buffer+=payload;
    }
예제 #2
0
int net_buffer_putShort(struct net_buffer * buf, uint16_t half)
{
    if (!buf) return -1;
    if ((buf->buf_ptr + sizeof(uint16_t)) > buf->buf+buf->size) return -1;

    putShort(buf->buf_ptr, half);
    buf->buf_ptr += sizeof(uint16_t);
    return 0;
}
예제 #3
0
파일: oututil.cpp 프로젝트: nealey/vera
//---------------------------------------------------------------------------
uchar out_index(ushort index, fmt_t mode, color_t ntag, uchar as_index)
{
  if ( as_index ) {
    if(   !(idpflags & (IDM_BADIDXSTR | IDM_OUTASM))   // no store in file
       || !is_valid_string_index(index)) return(putShort(index));
    ntag = COLOR_ERROR;
    mode = fmt_string;
  }
  return(OutUtf8(index, mode, ntag));
}
 encode()
 {
     Packet::encode();
     buffer+=ID;
     putMagic();
     putLong(serverId);
     putAddress(clientAddress,clientPort);
     putShort(mtuSize);
     putByte('\0');//server security
 }
예제 #5
0
파일: oututil.cpp 프로젝트: nealey/vera
//--------------------------------------------------------------------------
// end of special-label procedures
//----------------------------------------------------------------------
uchar outOffName(ushort off)
{
  if ( !off || off == curSeg.CodeSize) return(putMethodLabel(off) );
  if ( off < curSeg.CodeSize ) {
    uchar err = 0;
    if(outName(curSeg.startEA + curSeg.CodeSize, 0,
               curSeg.startEA, off, &err)) return(0); // good
    if ( err) return(1 ); // bad
  }
  return(putShort(off, 0));
}
int Generator::fillData(char *start, int frequency, int seconds)
{
    int i, len=0;
    int value;
    for(i=0; i<seconds*SYSTEM_FREQ; i++) {
        value=(int)(32767.0*sin(2.0*M_PI*((double)(i))*(double)(frequency)/SYSTEM_FREQ));
        putShort(start, value);
        start += 4;
        len+=2;
    }
    return len;
}
예제 #7
0
파일: cache.c 프로젝트: eruffaldi/pitos
static void 
releaseInlineCacheEntry(int index)
{
    ICACHE thisICache = &InlineCache[index];

    /*  Read the pointer to the code location  */
    /*  referring to this inline cache entry */
    BYTE* codeLoc = (BYTE*)thisICache->codeLoc;

    /*  Restore original bytecodes */
    *codeLoc = thisICache->origInst;
    putShort(codeLoc+1, thisICache->origParam);
}
예제 #8
0
파일: oututil.cpp 프로젝트: nealey/vera
//--------------------------------------------------------------------------
uchar putScope(ushort scope, uint32 doff)
{
  if ( !scope || scope == curSeg.CodeSize) return(putMethodLabel(scope) );

  if ( scope < curSeg.CodeSize ) {
    uchar err = 0;
    if(outName(curSeg.DataBase + doff, 0,
               curSeg.startEA, scope, &err)) return(0);
    if ( err) return(1 );
  }

  return(putShort(scope, 0));
}
예제 #9
0
파일: pr26222.c 프로젝트: 0day-ci/gcc
void f(int t1)
{
  int clutOffset = 52 + 256 * 3 * 2;
  int x, y, z;
  for (x = 0; x < 16; x++)
    for (y = 0; y < 16; y++)
      for (z = 0; z < 16; z++)
        {
          int offset = clutOffset + z * 6 + y * 16 * 6 + x * 16 * 16 * 6;
          double xf = ((double) x) / ((double) 16 - 1.0);
          double tt = xf;
          putShort(offset, tt);
        } 
}
예제 #10
0
파일: parse.c 프로젝트: coyizumi/cs111
void
convert_num(unsigned char *buf, char *str, int base, int size)
{
	int negative = 0, tval, max;
	u_int32_t val = 0;
	char *ptr = str;

	if (*ptr == '-') {
		negative = 1;
		ptr++;
	}

	/* If base wasn't specified, figure it out from the data. */
	if (!base) {
		if (ptr[0] == '0') {
			if (ptr[1] == 'x') {
				base = 16;
				ptr += 2;
			} else if (isascii(ptr[1]) && isdigit(ptr[1])) {
				base = 8;
				ptr += 1;
			} else
				base = 10;
		} else
			base = 10;
	}

	do {
		tval = *ptr++;
		/* XXX assumes ASCII... */
		if (tval >= 'a')
			tval = tval - 'a' + 10;
		else if (tval >= 'A')
			tval = tval - 'A' + 10;
		else if (tval >= '0')
			tval -= '0';
		else {
			warning("Bogus number: %s.", str);
			break;
		}
		if (tval >= base) {
			warning("Bogus number: %s: digit %d not in base %d",
			    str, tval, base);
			break;
		}
		val = val * base + tval;
	} while (*ptr);

	if (negative)
		max = (1 << (size - 1));
	else
		max = (1 << (size - 1)) + ((1 << (size - 1)) - 1);
	if (val > max) {
		switch (base) {
		case 8:
			warning("value %s%o exceeds max (%d) for precision.",
			    negative ? "-" : "", val, max);
			break;
		case 16:
			warning("value %s%x exceeds max (%d) for precision.",
			    negative ? "-" : "", val, max);
			break;
		default:
			warning("value %s%u exceeds max (%d) for precision.",
			    negative ? "-" : "", val, max);
			break;
		}
	}

	if (negative)
		switch (size) {
		case 8:
			*buf = -(unsigned long)val;
			break;
		case 16:
			putShort(buf, -(unsigned long)val);
			break;
		case 32:
			putLong(buf, -(unsigned long)val);
			break;
		default:
			warning("Unexpected integer size: %d", size);
			break;
		}
	else
		switch (size) {
		case 8:
			*buf = (u_int8_t)val;
			break;
		case 16:
			putUShort(buf, (u_int16_t)val);
			break;
		case 32:
			putULong(buf, val);
			break;
		default:
			warning("Unexpected integer size: %d", size);
			break;
		}
}
예제 #11
0
sp<ByteBuffer> ByteBuffer::putShort(int16_t value) {
    putShort(mPosition, value);
    mPosition += sizeof(value);
    return this;
}
예제 #12
0
static WMA_STATUS jsr205_datagram_write(jint outPort, void* handle, char *toAddr,
    char* fromAddr, jint length, char* buf, jint *bytesWritten) {

    /** The maximum amount of data allowed within a network packet. */
    jint PACKET_MAX_SIZE = MAX_DATAGRAM_LENGTH - 10;  /* 3 shorts + 1 int */

    /** The socket descriptor that corresponds to the handle. */
    jint socket_fd;

    /** The total number of datagram packets to be sent. */
    jshort totalPackets;

    /** The current packet number. */
    jshort packetNumber;

    /** The IP address used for datagram transfers. */
    unsigned char ipAddr[256];

    /** The length of the IP address to be retrieved. */
    int plen = 0;

    struct sockaddr_in addr;

    /** The buffer for all datagram data. */
    char* dgramBuffer = NULL;

    /** The writing index into the datagram buffer. */
    jint index = 0;

    /** The running pointer to the data to be sent, chunk by chunk. */
    char* p = buf;   /* pointer into buf */

    /** The count of bytes for the current chunk of data to be sent. */
    jint count = 0;

    jint status = WMA_NET_IOERROR;

    /*
     * The "to" and "from" addresses are not used in this implementation. In a
     * more sophisticated implementation that may involve more than one
     * recipient, the packets that get broadcast would need to be directed to
     * specific phones. The "to" address would then come into play and would
     * need to be for each specific phone in a phone list.
     */
    (void)toAddr;
    (void)fromAddr;

    /* Pick up the socket descriptor that corresponds to the handle. */
    socket_fd = wmaGetRawSocketFD(handle);

    *bytesWritten = 0;

    /* Compute the total number of datagrams required to send the message. */
    totalPackets =
        (jshort)((length + PACKET_MAX_SIZE - 1) / PACKET_MAX_SIZE);

    for (packetNumber = 1; packetNumber <= totalPackets; packetNumber++) {

        /** Reset the writing index into the datagram buffer. */
        index = 0;

        if (dgramBuffer == NULL) {
            /* Allocate datagram buffer */
            dgramBuffer = (char*)pcsl_mem_malloc(MAX_DATAGRAM_LENGTH);
        }

        if (dgramBuffer != NULL) {

            /* Initialize the datagram buffer. */
            memset(dgramBuffer, 0, MAX_DATAGRAM_LENGTH);

            /* Compute the number of bytes that can be stuffed into
             * this packet. 
             */
            count = length;
            if (count > PACKET_MAX_SIZE) {
                count = PACKET_MAX_SIZE;
            }

            /* Build the buffer to be written */
            putShort(dgramBuffer, &index, packetNumber);
            putShort(dgramBuffer, &index, totalPackets);
            /* Needed for: count < PACKET_MAX_SIZE */
            putShort(dgramBuffer, &index, count);
            /* Total length of message. */
            putInt(dgramBuffer, &index, length);
            /* Writes count bytes, starting at p. */
            putBytes(dgramBuffer, &index, p, count);

            memset(ipAddr, 0, 256);

            /* Send the datagram into the ether. */
            if (network_gethostbyname(targetHost, ipAddr, 256, &plen)
                != WMA_NET_SUCCESS) {

                return WMA_NET_IOERROR;
            }

            addr.sin_family = AF_INET;
            addr.sin_port   = htons((unsigned short)outPort);
            memcpy(&addr.sin_addr.s_addr, ipAddr,
                   sizeof(addr.sin_addr.s_addr));

            status = sendto(socket_fd, dgramBuffer, MAX_DATAGRAM_LENGTH,
                0, (struct sockaddr*)&addr, sizeof(addr));

            if (SOCKET_ERROR == status) {
                if (EWOULDBLOCK == errno || EINPROGRESS == errno) {
                    status = WMA_NET_WOULDBLOCK;
                } else if (EINTR == errno) {
                    status = WMA_NET_INTERRUPTED;
                } else {
                    status = WMA_NET_IOERROR;
                }
                break;
            }

            *bytesWritten += status;

            status = WMA_NET_SUCCESS;

            /* Move the pointer past the bytes and do next send */
            p += count;
            length -= count;
        }
    }

    /* If a datagram buffer was used, be sure to free its memory. */
    pcsl_mem_free(dgramBuffer);

    return (WMA_STATUS)status;
}