예제 #1
0
bool Processor::sendRegFile(const char *filepath,File &file,Header &header)
{

    char buffer[BUF_MAXLEN];
    size_t len;
    bool res = file.open(filepath);


    if(!res)
    {
        handleError(REPLY_NOENT);
        goto out;

    }

    len = file.size();
    if(!len){
        handleError(REPLY_INTERR);
        res = false;
        goto out;
    }

    header.addReply(REPLY_OK);
    header.addDate();
    header.addServer();
    header.addLength(len);
    header.addType(filepath);
    header.addEnd();

    res = sendHeader(header);

    if(!res)
        goto out;
    while(len){
        size_t ret,size;

        size = (len>BUF_MAXLEN) ? BUF_MAXLEN:len;
        res = file.read(buffer,size);
        if(!res)
            break;
        ret = write(buffer,size);
        if(ret!=size){
            res = false;
            break;
        }

        len -= size;
    }
out:
    file.close();
    return res;
}
예제 #2
0
bool Processor::send(const void *buffer,size_t len,int reply)
{
    Header header;
    size_t res;
    bool ret;

    header.addReply(reply);
    header.addDate();
    header.addServer();
    if(len>0) header.addLength(len);
    header.addEnd();

    ret = sendHeader(header);
    if(!ret)
        return false;
    if(len>0){
        res = write(buffer,len);
        if(res<=0)
            return false;
    }    
    return true;
}
예제 #3
0
bool Processor::sendDir(const char *filepath,File &file,Header &header)
{

    bool res = true;

    const char *buffer;
    int len;
    struct stat sbuf;
    string data;
    file.type(filepath,&sbuf);

    if(!res)
    {
        handleError(REPLY_NOENT);
        goto out;

    }

    len = sbuf.st_size;
    cout << len << "***"<<endl;
    if(!len){
        handleError(REPLY_INTERR);
        res = false;
        goto out;
    }

    header.addReply(REPLY_OK);
    header.addDate();
    header.addServer();
    header.addLength(len);
    header.addEnd();

    res = sendHeader(header);

    if(!res)
        goto out;
  //  while(len){
   //     size_t ret,size;

    //    size = (len>BUF_MAXLEN) ? BUF_MAXLEN:len;
     //   res = file.read(buffer,size);

        //if(!res)
         //   break;
    size_t size;
        data = Page::dirPage(filepath);
        buffer = data.c_str();
        size = data.length();
        res = write(buffer,size);
     //   if(ret!=size){
      //      res = false;
       //     break;
        //}

        //len -= size;
   // }
    
   // file.close();
out:

    return res;

}