17 #include <gflags/gflags.h> 26 using namespace folly;
36 if (filename ==
"bye") {
40 int fd = open(filename.c_str(), O_RDONLY);
49 if (fstat(fd, &buf) == -1) {
56 FileRegion fileRegion(fd, 0, buf.st_size);
59 .onError([
this,
guard, ctx, filename](
const std::exception& e){
68 .thenValue([
this, ctx](
auto&&) {
close(ctx); });
74 write(ctx,
"Welcome to " + localAddress.
describe() +
"!\r\n");
75 write(ctx,
"Type the name of a file and it will be streamed to you!\r\n");
76 write(ctx,
"Type 'bye' to exit.\r\n");
83 std::shared_ptr<AsyncTransportWrapper> sock)
override {
99 server.
childPipeline(std::make_shared<FileServerPipelineFactory>());
100 server.
bind(FLAGS_port);
void write(const T &in, folly::io::Appender &appender)
void transportActive(Context *ctx) override
std::shared_ptr< folly::AsyncTransport > getTransport()
std::string sformat(StringPiece fmt, Args &&...args)
void bind(folly::AsyncServerSocket::UniquePtr s)
int main(int argc, char **argv)
fbstring exceptionStr(const std::exception &e)
—— Concurrent Priority Queue Implementation ——
std::string describe() const
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
void init(int *argc, char ***argv, bool removeFlags)
DEFINE_int32(port, 11219,"test file server port")
GuardImpl guard(ErrorHandler &&handler)
std::shared_ptr< Pipeline > Ptr
Pipeline< IOBufQueue &, std::string > FileServerPipeline
FileServerPipeline::Ptr newPipeline(std::shared_ptr< AsyncTransportWrapper > sock) override
virtual std::shared_ptr< PipelineBase > getPipelineShared()=0
int close(NetworkSocket s)
void readException(Context *ctx, exception_wrapper ew) override
void read(Context *ctx, std::string filename) override