示例#1
0
void clientBid()
{
    printf("Trying to bid...\n");
    makeBuf(2, NULL);   
    if(sendto(client_sockfd, buf, BUFSIZ, 0, (struct sockaddr *) & server_addr, sizeof(struct sockaddr)) < 0)
    {
        perror("Bidding failed");
        close(client_sockfd);
        exit(EXIT_FAILURE);
    }
}
示例#2
0
void clientRefresh()
{
    printf("Requesting latest auction state...\n");
    makeBuf(1, NULL);   
    if(sendto(client_sockfd, buf, BUFSIZ, 0, (struct sockaddr *) & server_addr, sizeof(struct sockaddr)) < 0)
    {
        perror("Refresh failed");
        close(client_sockfd);
        exit(EXIT_FAILURE);
    }
}
示例#3
0
void clientLeave()
{
    printf("Leaving ...\n");
    makeBuf(3, NULL);   
    if(sendto(client_sockfd, buf, BUFSIZ, 0, (struct sockaddr *) & server_addr, sizeof(struct sockaddr)) < 0)
    {
        perror("Leaving failed");
        close(client_sockfd);
        exit(EXIT_FAILURE);
    }
}
示例#4
0
void clientLoggin()
{
    char userName[20];
    printf("Enter your name\n(Note: Other bidders won't see this):");
    scanf("%s", userName);
    makeBuf (0, userName);  
    printf("Loggin as %s ...", userName);
    if(sendto(client_sockfd, buf, BUFSIZ, 0, (struct sockaddr *) & server_addr, sizeof(struct sockaddr)) < 0)
    {
        perror("Loggin failed");
        close(client_sockfd);
        exit(EXIT_FAILURE);
    }
    memset(buf, 0, sizeof(buf));
    if((len = recvfrom(client_sockfd, buf, BUFSIZ, 0, (struct sockaddr *) & server_addr, &sin_size)) < 0)
    {
        perror("recvfrom");
    }
    puts(buf);  
    getchar();
}
示例#5
0
void fakeMockCodec(MockHTTPCodec& codec) {
  // For each generate* function, write some data to the chain
  EXPECT_CALL(codec, generateHeader(_, _, _, _, _))
      .WillRepeatedly(Invoke(
          [](folly::IOBufQueue& writeBuf,
             HTTPCodec::StreamID /*stream*/,
             const HTTPMessage& /*msg*/,
             bool /*eom*/,
             HTTPHeaderSize* /*size*/) { writeBuf.append(makeBuf(10)); }));

  EXPECT_CALL(codec, generatePushPromise(_, _, _, _, _, _))
      .WillRepeatedly(Invoke(
          [](folly::IOBufQueue& writeBuf,
             HTTPCodec::StreamID /*stream*/,
             const HTTPMessage& /*msg*/,
             HTTPCodec::StreamID /*assocStream*/,
             bool /*eom*/,
             HTTPHeaderSize* /*size*/) { writeBuf.append(makeBuf(10)); }));

  EXPECT_CALL(codec, generateBody(_, _, _, _, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf,
                                HTTPCodec::StreamID /*stream*/,
                                std::shared_ptr<folly::IOBuf> chain,
                                folly::Optional<uint8_t> /*padding*/,
                                bool /*eom*/) {
        auto len = chain->computeChainDataLength();
        writeBuf.append(chain->clone());
        return len;
      }));

  EXPECT_CALL(codec, generateChunkHeader(_, _, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf,
                                HTTPCodec::StreamID /*stream*/,
                                size_t length) {
        writeBuf.append(makeBuf(length));
        return length;
      }));

  EXPECT_CALL(codec, generateChunkTerminator(_, _))
      .WillRepeatedly(Invoke(
          [](folly::IOBufQueue& writeBuf, HTTPCodec::StreamID /*stream*/) {
            writeBuf.append(makeBuf(4));
            return 4;
          }));

  EXPECT_CALL(codec, generateTrailers(_, _, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf,
                                HTTPCodec::StreamID /*stream*/,
                                const HTTPHeaders& /*trailers*/) {
        writeBuf.append(makeBuf(30));
        return 30;
      }));

  EXPECT_CALL(codec, generateEOM(_, _))
      .WillRepeatedly(Invoke(
          [](folly::IOBufQueue& writeBuf, HTTPCodec::StreamID /*stream*/) {
            writeBuf.append(makeBuf(6));
            return 6;
          }));

  EXPECT_CALL(codec, generateRstStream(_, _, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf,
                                HTTPCodec::StreamID /*stream*/,
                                ErrorCode /*code*/) {
        writeBuf.append(makeBuf(6));
        return 6;
      }));

  EXPECT_CALL(codec, generateGoaway(_, _, _, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf,
                                uint32_t /*lastStream*/,
                                ErrorCode,
                                std::shared_ptr<folly::IOBuf>) {
        writeBuf.append(makeBuf(6));
        return 6;
      }));

  EXPECT_CALL(codec, generatePingRequest(_))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generatePingReply(_, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf, uint64_t /*id*/) {
        writeBuf.append(makeBuf(6));
        return 6;
      }));

  EXPECT_CALL(codec, generateSettings(_))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generateWindowUpdate(_, _, _))
      .WillRepeatedly(Invoke([](folly::IOBufQueue& writeBuf,
                                HTTPCodec::StreamID /*stream*/,
                                uint32_t /*delta*/) {
        writeBuf.append(makeBuf(6));
        return 6;
      }));
}
示例#6
0
std::tuple<std::unique_ptr<HTTPMessage>, std::unique_ptr<folly::IOBuf> >
makeResponse(uint16_t statusCode, size_t len) {
  auto resp = makeResponse(statusCode);
  resp->getHeaders().set(HTTP_HEADER_CONTENT_LENGTH, folly::to<string>(len));
  return std::make_pair(std::move(resp), makeBuf(len));
}
示例#7
0
void fakeMockCodec(MockHTTPCodec& codec) {
  // For each generate* function, write some data to the chain
  EXPECT_CALL(codec, generateHeader(_, _, _, _, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream,
                               const HTTPMessage& msg,
                               HTTPCodec::StreamID assocStream,
                               bool eom,
                               HTTPHeaderSize* size) {
                             writeBuf.append(makeBuf(10));
                           }));

  EXPECT_CALL(codec, generateBody(_, _, _, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream,
                               std::shared_ptr<folly::IOBuf> chain,
                               boost::optional<uint8_t> padding,
                               bool eom) {
                             auto len = chain->computeChainDataLength();
                             writeBuf.append(chain->clone());
                             return len;
                           }));

  EXPECT_CALL(codec, generateChunkHeader(_, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream,
                               size_t length) {
                             writeBuf.append(makeBuf(length));
                             return length;
                           }));

  EXPECT_CALL(codec, generateChunkTerminator(_, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream) {
                             writeBuf.append(makeBuf(4));
                             return 4;
                           }));

  EXPECT_CALL(codec, generateTrailers(_, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream,
                               const HTTPHeaders& trailers) {
                             writeBuf.append(makeBuf(30));
                             return 30;
                           }));

  EXPECT_CALL(codec, generateEOM(_, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generateRstStream(_, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream,
                               ErrorCode code) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generateGoaway(_, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               uint32_t lastStream,
                               ErrorCode code) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generatePingRequest(_))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generatePingReply(_, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               uint64_t id) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generateSettings(_))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

  EXPECT_CALL(codec, generateWindowUpdate(_, _, _))
    .WillRepeatedly(Invoke([] (folly::IOBufQueue& writeBuf,
                               HTTPCodec::StreamID stream,
                               uint32_t delta) {
                             writeBuf.append(makeBuf(6));
                             return 6;
                           }));

}