Giter Site home page Giter Site logo

acassen / socket-takeover Goto Github PK

View Code? Open in Web Editor NEW
43.0 1.0 9.0 23 KB

Socket takeover from one process to another

License: GNU General Public License v2.0

Makefile 5.67% C 94.33%
high-availability socket-programming socket-takeover takeover

socket-takeover's Introduction

Socket Takeover: Socket takeover from one process to another

When you are running business mission critical services you MUST rely on design offering zero downtime. It is truly the case when considering upgrading/updating such mission critical software components.

This software introduce a design pattern to perform seamless TCP socket takeover from one process to another. The code here is just a proof of concept and can be used for experimentation or integration into more complex software component.

This source code is using design present in 4.4BSD systems. Using SCM_RIGHTS ancillary data over a Unix domain socket to transport a set of file descriptors. You can find more informations on this technic by reading good litterature from [W. Richard Stevens: UNIX Network Programming Volume 1 Third Edition], section 15.7. The code proposed here will make it more Linux specific by introducting a mechanism to takeover and synchronize client/server interactions.

Content

2 directories are available :

* server : TCP server code
* client : TCP client code

Give it a try : Server side

$ cd server
$ make
$ ./server -h
Usage: ./server [OPTION...]
  -a, --listen-address		Address to bind TCP listener on
  -p, --listen-port		Port to bind TCP listener on
  -b, --listen-backlog		TCP listener backlog
  -t, --takeover-path		Takeover channel unix domain path
  -T, --takeover		Perform takeover operation
  -h, --help			Display this help message
$ ./server -a 127.0.0.1 -p 1234 -t /tmp/.takeover

Give it a try : Client side

$ cd client
$ make
$ ./client -h
Usage: ./client [OPTION...]
  -a, --connect-address		Connection Address
  -p, --connect-port		Connection Port
  -h, --help			Display this help message
$ ./client -a 127.0.0.1 -p 1234

Having fun

[client]$ ./client -a 127.0.0.1 -p 1234


[server/sh1]$ ./server -a 127.0.0.1 -p 1234 -t /tmp/.takeover
Starting TCP server on [127.0.0.1]:1234 (fd:3)
Starting Takeover channel on [/tmp/.takeover] domain socket
Accepting connection from Peer [127.0.0.1]:57796 (fd:4)
Starting connection with Peer [127.0.0.1]:57796 (fd:4)
[127.0.0.1]:57796 - seqnum:0
[127.0.0.1]:57796 - seqnum:1
[127.0.0.1]:57796 - seqnum:2
[127.0.0.1]:57796 - seqnum:3
[127.0.0.1]:57796 - seqnum:4
[127.0.0.1]:57796 - seqnum:5
[127.0.0.1]:57796 - seqnum:6
[127.0.0.1]:57796 - seqnum:7
[127.0.0.1]:57796 - seqnum:8
[127.0.0.1]:57796 - seqnum:9
[127.0.0.1]:57796 - seqnum:10
[127.0.0.1]:57796 - seqnum:11
[127.0.0.1]:57796 - seqnum:12
[127.0.0.1]:57796 - seqnum:13
[127.0.0.1]:57796 - seqnum:14
[127.0.0.1]:57796 - seqnum:15
[127.0.0.1]:57796 - seqnum:16
[127.0.0.1]:57796 - seqnum:17
[127.0.0.1]:57796 - seqnum:18
[127.0.0.1]:57796 - seqnum:19
Accepting connection from Takeover channel
Current fd_array:={[3][4]}
[127.0.0.1]:57796 - seqnum:20
Holding connection with Peer [127.0.0.1]:57796 (fd:4)
Releasing Peer [127.0.0.1]:57796 (fd:4)
tcp_peer_release(): Tcp peers released...


[server/sh2]$ ./server -T /tmp/.takeover 
Starting connection with Peer [127.0.0.1]:57796 (fd:5)
Starting Takeover channel on [/tmp/.takeover] domain socket
[127.0.0.1]:57796 - seqnum:21
[127.0.0.1]:57796 - seqnum:22
[127.0.0.1]:57796 - seqnum:23
[127.0.0.1]:57796 - seqnum:24
[127.0.0.1]:57796 - seqnum:25
[127.0.0.1]:57796 - seqnum:26
[127.0.0.1]:57796 - seqnum:27
[127.0.0.1]:57796 - seqnum:28
[127.0.0.1]:57796 - seqnum:29
...

Enjoy, Alexandre

socket-takeover's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.