Code Monkey home page Code Monkey logo

simple-web-proxy's Introduction

vProxy

A simple http proxy that deploy in clent end.

workflow of web proxy

CLIENT --- (1)http request ---> PROXY --- (2)http request ---> SERVER
CLIENT <-- (4)http response --- PROXY <-- (3)http response --- SERVER

+--------+                            +-------+                           +--------+
|        | -- (1)TCP connection ----> |       |                           |        |
|        | -- (2)http request ------> |       | --- (3)TCP connection --> |        |
|        |                            |       | --- (4)http request ----> |        |
| CLIENT |                            | PROXY |                           | SERVER |
|        | <- (6)http response ------ |       | <-- (5)http response ---  |        |
|        |         ...                |       |          ...              |        |
|        |                            |       |                           |        |
|        | <- (n+1)close connection - |       | <-- (n)close connection - |        |
+--------+                            +-------+                           +--------+

close vs shutdown

close() will prevent any more reads and writes to the socket and free it.

int shutdown(int sockfd, int how);

The  shutdown()  call  causes  all  or part of a full-duplex connection on the socket associated with sockfd to be shut down.  If how is SHUT_RD, further receptions will be disallowed.  If how is SHUT_WR, further transmissions will be disallowed.  If how is SHUT_RDWR, further receptions and transmissions will be disallowed.
But shutdown() doesn't free a the socket descriptor.

read/write vs recv/send

read() is equivalent to recv() with a flags parameter of 0. Other values for the flags parameter change the behaviour of recv(). Similarly, write() is equivalent to send() with flags == 0.

MSG_DONTWAIT (since Linux 2.2)
    Enables nonblocking operation; if the operation would block,
    the call fails with the error EAGAIN or EWOULDBLOCK.
    [reference](http://man7.org/linux/man-pages/man2/recv.2.html)

errno

read

EAGAIN or EWOULDBLOCK: The file descriptor fd refers to a socket and has been marked 
                       nonblocking (O_NONBLOCK), and the read would block.
EBADF: fd is not a valid file descriptor or is not open for reading.

write

EAGAIN or EWOULDBLOCK: The file descriptor fd refers to a socket and has been marked
                       nonblocking (O_NONBLOCK), and the write would block.
EBADF: fd is not a valid file descriptor or is not open for writing.
EPIPE: fd is connected to a pipe or socket whose reading end is closed.

dependencies

reference

simple-web-proxy's People

Contributors

onestraw avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.