Esempio n. 1
0
void AutoUpdaterImpl::init() {
  time_t now(time(NULL));
  char st[256];

  msgbox("update: init called.\n");

  if(now < config.info3.last_update + mindelay) {
    now = config.info3.last_update + mindelay;
    msgbox("update: updated too recently, not before %s", ctime(&now));
    ret();
    return;
  }

  buf.resize(0);
  buf.append("GET "UPDATE_PATH" HTTP/1.0\r\n");
  buf.append("Host: "UPDATE_HOST"\r\n");
  buf.append("Connection: close\r\n");
  snprintf(st, sizeof(st), "User-Agent: Quadra/%s\r\n", VERSION_STRING);
  buf.append(st);
  if(*config.info3.last_modified) {
    msgbox("update: setting If-Modified-Since to %s\n",
	   config.info3.last_modified);
    buf.append("If-Modified-Since: ");
    buf.append(config.info3.last_modified);
    buf.append("\r\n");
  } else
    msgbox("update: not setting If-Modified-Since\n");
  buf.append("\r\n");
  req = new Http_request(UPDATE_HOST, UPDATE_PORT, buf.get(), buf.size());
}
Esempio n. 2
0
int SendTask::work() {
    while(true){
        Buf* p = NULL;
        if (0 != SINGLE->sendqueue.dequeue(p, 3)) {
            continue;
        }

        int fd = p->getfd();

        if (0 == fd) {
            printf(" fd = 0 !\n");
            continue;
        }

#if 0
        MSG_HEAD* pp = (MSG_HEAD*)p->ptr();
        if ( pp->cType > 9999 ) {
            struct sGetAllStudentInfo* xxx = (struct sGetAllStudentInfo*)pp->cData();
            printf("id %d pic %s  --  len:=%d\n", xxx->iStudentId, xxx->sPicName, pp->cLen);

        }

        unsigned int len = 0;
        int cnt;
        while (len < p->size()) {
            cnt = send(fd, (char *)p->ptr() + len, p->size() - len, 0);
            if (cnt == -1) {
                cout << "send erroooooooooooooooooooooor" << endl;
                break;
            }
            len += cnt;
        }

        printf ("ERRNO: %d, message:%s len = %d, p->size() = %ld\n", errno, strerror (errno), len ,p->size());
#else
        int bytes_left = p->size ();
        int written_bytes;
        char* ptr = (char*) p->ptr();
        while (bytes_left > 0)
        {
            written_bytes = send (fd, ptr, bytes_left, 0);
            if (written_bytes <= 0) {
                if (errno == EINTR) {
                    if (written_bytes < 0) written_bytes = 0;
                    continue;
                }
                else if (errno == EAGAIN) {
                    if (written_bytes < 0) written_bytes = 0;
                    sleep (1);
                    continue;
                }
                else
                    break;
            }
            bytes_left -= written_bytes;
            ptr += written_bytes;
        }
#endif
        printf("Send data...finished. packetLength=%ld, from FD=[%d]\n", p->size(), fd);

        p->reset();
        SINGLE->bufpool.free(p);
    }
    return 0;
}
Esempio n. 3
0
int SendTask::work ()
{
    while (true)
    {
        Buf* p = NULL;
        if (SINGLE->sendqueue.dequeue (p, 3) != 0)
        {
            continue;
        }

        int fd = p->getfd ();

        if (fd <= 0)
        {
            cout << "[SEND] -- fd of buffer <= 0" << endl;
            SINGLE->bufpool.free (p);
            continue;
        }

        //
#if 0
        cout << "Send cType: " << ((MSG_HEAD*)p->ptr())->cType <<endl;
        printf ("address: %p\n", p);
        if (((MSG_HEAD*)p->ptr())->cType == 187) {
        cout << "-----------------------BEGIN-------------------------------------" << endl;
        cout << "CTYPE: " << ((MSG_HEAD*) (p->ptr()))->cType << endl;
        cout << "LEN: " << *(unsigned int*) ((char*)p->ptr() + MSG_HEAD_LEN) << endl;
        cout << "STUDENT_ID: " << *(unsigned int*) ((char*)p->ptr() + MSG_HEAD_LEN + sizeof (unsigned int)) << endl;
        cout << "STATUS: " << *(unsigned int*) ((char*)p->ptr() + MSG_HEAD_LEN + sizeof (int) + sizeof (int)) << endl;
        cout << "STUDENT_ID: " << *(unsigned int*) ((char*)p->ptr() + MSG_HEAD_LEN + sizeof (int) + sizeof (int) + sizeof (int)) << endl;
        cout << "STATUS: " << *(unsigned int*) ((char*)p->ptr() + MSG_HEAD_LEN + sizeof (int) + sizeof (int)+ sizeof (int) + sizeof (int)) << endl;

        cout << "-------------------------END-----------------------------------" << endl;
        }
#endif

        // send fck message to clients
        // must be need written bytes data finished
        debugProtocol (p);
        int bytes_left = p->size ();
        int written_bytes;
        char* ptr = (char*) p->ptr();
        while (bytes_left > 0)
        {
            written_bytes = send (fd, ptr, bytes_left, 0);
            if (written_bytes <= 0) {
                if (errno == EINTR) {
                    if (written_bytes < 0) {
                        written_bytes = 0;
                        cout << "EINTR......" << endl;
                        continue;
                    }
                }
                else if (errno == EAGAIN) {
                    if (written_bytes < 0) {
                        written_bytes = 0;
                        usleep (50);
                        cout << "EAGAIN......" << endl;
                        continue;
                    }
                }
                else {
                    break;
                }
            }
            bytes_left -= written_bytes;
            ptr += written_bytes;
        }

        //printf("Send data...finished. packetLength=%ld, from FD=[%d]\n", p->size(), fd);
        LOG(INFO) << "Send data ... finished. packet len=" << p->size() << ", from FD=" << fd << endl;

        p->reset ();
        SINGLE->bufpool.free (p);
    }
    return 0;
}