Exemplo n.º 1
0
ssize_t ReadLine(int fd,char *buffer) {
    /* TODO: change with bufferful read, or fixed byte size read*/
    /* reads a line from fd to buffer. Line feed included. */
    int chrCount=0;
    ssize_t byteRead;
    char buf;
    do{
        if( (byteRead = sRead(fd, &buf, 1)) > 0) {
            buffer[chrCount] = buf;
            chrCount ++;
            if(buf == '\n'){
                /*we got new line */
                buffer[chrCount] = '\0'; /*terminate the string*/
                return chrCount;
            }
        }
    } while(chrCount <= strlen(buffer) &&  byteRead !=0);
    return 0;/*no line feed was found */
}
int ReceiveData2(int sourcefd, int targetfd, unsigned long int *filesize)
{
  long             nread=0, nwrite, ns=0, nt, readsize;
  char             buff[MAXBUFFLEN], *buffptr;
  struct ibp_timer timeout;

/*//  fprintf(stderr,"IN RECEIVE DATA 2 <%s>\n",glb.IBP_cap);*/

  timeout.ServerSync = 10;
  timeout.ClientTimeout = 10;
  while (nread < *filesize) {  
    readsize = min(*filesize-nread,MAXBUFFLEN);
    bzero(buff,MAXBUFFLEN);
    ns = sRead(sourcefd, buff, readsize);
    if (ns < 0){
      perror("serverTCP: error reading from socket");
      return -1; 
    }
    nwrite = 0; 
    buffptr = buff;
    while (nwrite < ns) { 

#ifdef IBP_DEBUG   
      fprintf(stderr,"#");
#endif
      /**nt = sWrite(targetfd, buffptr, ns-nwrite);*/
      nt = IBP_store(glb.IBP_cap, &timeout, buffptr, ns-nwrite);
      if (nt < 0){
	fprintf(stderr,"UP TO NOW: %d\n",nwrite);
	perror("serverTCP: error writing to local storage");
	return -1;
      }
      buffptr += nt;
      nwrite += nt;
    }
    nread += ns;
  }
  
  *filesize = nread;
  write(sourcefd,"FIN",3);
  return 1;
}
Exemplo n.º 3
0
void handleRequest(char *buffer)
{
	msg_t *msg = (msg_t *)buffer;
	
	switch(msg->func){
		case LOOKUP:
			msg->retCode=sLookup(msg->pinum, msg->name);
			break;
		case STAT:
			msg->retCode=sStat(msg->inum, &(msg->stat));
			break;
		case WRITE:
			//printf("Got\n%s\n", msg->buffer);
			msg->retCode=sWrite(msg->inum, msg->buffer, msg->block);
			break;
		case READ:
			msg->retCode=sRead(msg->inum, msg->buffer, msg->block);
			break;
		case CREAT:
		{//need this bracket to define a scope for variable declaration
			//MFS_Stat_t *stat = &(msg->stat); 
			msg->retCode=sCreat(msg->pinum, msg->type, msg->name);	
			break;
		}
		case UNLINK:
			msg->retCode=sUnlink(msg->pinum, msg->name);
			break;
		case SHUTDOWN:
			msg->retCode=0;
			fsync(fdImage);
			close(fdImage);
			UDP_Write(sd,&addr,(char*)msg, sizeof(msg_t));
			exit(0);
			break;
		default:
			msg->retCode=-1;
			break;
	}

}
Exemplo n.º 4
0
void TXFFont::initFromStream(std::istream &source)
{
    bool    swapit, valid = true;
    UChar8  u_magic, *imageBuffer = NULL;
    Char8   c_magic[3];
    UInt32  ibuff, bitWidth = 0, stride;
    UInt16  sbuff;
    Int32   i, j;

    valid &= !source.fail();
    // checking sourcetype
    source >> u_magic;
    valid &= !source.fail();

    if(!(u_magic == 0xff))
        valid = false;

    source.read(c_magic, 3);
    valid &= !source.fail();

    if(strncmp(c_magic, "txf", 3))
        valid = false;

    source.read(reinterpret_cast < Char8 * > (&ibuff), 4);
    valid &= !source.fail();
    swapit = (ibuff == 0x12345678 ? false : true);

    if(swapit && (ibuff - 0x78563412))
        valid = false;

    valid &= sRead(source, &_txfIsBitmap, 4, swapit);
    valid &= sRead(source, &_txfFontWidth, 4, swapit);
    valid &= sRead(source, &_txfFontHeight, 4, swapit);
    valid &= sRead(source, &_txfFontMaxAscent, 4, swapit);
    valid &= sRead(source, &_txfFontMaxDescent, 4, swapit);
    valid &= sRead(source, &_txfNumGlyphs, 4, swapit);

    valid &= !(_txfIsBitmap > 1);

    _txfFontMaxDescent =
        _txfFontMaxDescent > 0 ? _txfFontMaxDescent * -1 : _txfFontMaxDescent;

    if(!valid)
    {
        _valid = valid;
        return;
    }

    // read content: glyph info
    _txfGlyphs = new txfChar[256];

    for(i = 0; i < _txfNumGlyphs; i++)
    {
        valid &= sRead(source, &sbuff, 2, swapit);
        source.read(reinterpret_cast<Char8 *>(
                        _txfGlyphs[UChar8(sbuff)].dimensions), 6);
        valid &= sRead(source, &_txfGlyphs[UChar8(sbuff)].x, 2, swapit);
        valid &= sRead(source, &_txfGlyphs[UChar8(sbuff)].y, 2, swapit);
        _txfGlyphs[UChar8(sbuff)].remapped = 0;

        if(!valid)
        {
            delete [] _txfGlyphs;

            _txfGlyphs = NULL;
            _valid = valid;

            return;
        }
    }

    if(_txfIsBitmap)
    {
        bitWidth = (_txfFontWidth + 7) / 8;
        imageBuffer = new UChar8[bitWidth * _txfFontHeight];
        source.read(reinterpret_cast < Char8 * > (imageBuffer),
                    bitWidth * _txfFontHeight);
    }
    else
    {
        imageBuffer = new UChar8[_txfFontWidth * _txfFontHeight];
        source.read(reinterpret_cast < Char8 * > (imageBuffer),
                    _txfFontWidth * _txfFontHeight);
    }

    valid &= !source.fail();

    if(!valid)
    {
        delete [] _txfGlyphs;
        delete [] imageBuffer;

        _txfGlyphs   = NULL;
        imageBuffer = NULL;
        _valid = valid;

        return;
    }

    _txfImageMap = new UChar8[_txfFontWidth * _txfFontHeight * 2];

    stride = 0;

    if(_txfIsBitmap)
    {
        for(i = 0; i < _txfFontHeight; i++)
        {
            for(j = 0; j < _txfFontWidth; j++, stride += 2)
            {
                _txfImageMap[stride] = _txfImageMap[stride + 1] =
                                           imageBuffer[i * bitWidth + (j >> 3)] &
                                           (1 << (j & 7)) ? 255 : 0;
            }
        }
    }
    else
    {
        for(i = 0; i < _txfFontHeight; i++)