/* ------------------------------------------------------------ */
    protected void onResponseHeader(Buffer name, Buffer value) throws IOException {
      super.onResponseHeader(name, value);
      if (HttpHeaders.CACHE.getOrdinal(name) == HttpHeaders.SET_COOKIE_ORDINAL) {
        String cname = null;
        String cvalue = null;

        QuotedStringTokenizer tok = new QuotedStringTokenizer(value.toString(), "=;", false, false);
        tok.setSingle(false);

        if (tok.hasMoreElements()) cname = tok.nextToken();
        if (tok.hasMoreElements()) cvalue = tok.nextToken();

        Cookie cookie = new Cookie(cname, cvalue);

        while (tok.hasMoreTokens()) {
          String token = tok.nextToken();
          if ("Version".equalsIgnoreCase(token))
            cookie.setVersion(Integer.parseInt(tok.nextToken()));
          else if ("Comment".equalsIgnoreCase(token)) cookie.setComment(tok.nextToken());
          else if ("Path".equalsIgnoreCase(token)) cookie.setPath(tok.nextToken());
          else if ("Domain".equalsIgnoreCase(token)) cookie.setDomain(tok.nextToken());
          else if ("Expires".equalsIgnoreCase(token)) {
            tok.nextToken();
            // TODO
          } else if ("Max-Age".equalsIgnoreCase(token)) {
            tok.nextToken();
            // TODO
          } else if ("Secure".equalsIgnoreCase(token)) cookie.setSecure(true);
        }

        BayeuxClient.this.setCookie(cookie);
      }
    }
  /* (non-Javadoc)
   * @see org.mortbay.io.EndPoint#fill(org.mortbay.io.Buffer)
   */
  public int fill(Buffer buffer) throws IOException {
    Buffer buf = buffer.buffer();
    int len = 0;

    NIOBuffer nbuf = (NIOBuffer) buf;
    ByteBuffer bbuf = nbuf.getByteBuffer();

    synchronized (nbuf) {
      try {
        if (bbuf.position() == 0) {
          bbuf.position(buffer.putIndex());
          len = _channel.read(bbuf);
        }
      } finally {
        buffer.setPutIndex(bbuf.position());
        bbuf.position(0);
      }
    }

    return len;
  }