Code Monkey home page Code Monkey logo

fortran-server's Introduction

This repo contains experimental code porting some simple C server code from Beej's Guide to Network Programming to Fortran.

It should work on OSX, and hopefully, eventually, other platforms as well.

Why would anyone...?

I'm learning Fortran, and this seemed like an interesting challenge. I don't think any sane person would ever want to actually try to write a production web service in Fortran.

Running the code

Run make to compile, then ./server. This will bind to port 3491, send "hello world" to clients that connect, with nc localhost 3491 for example, and print the connecting IP address.

The makefile passes the -g flag to compilers for debugging aid.

Notes on the code

It uses some modern Fortran 2003 features, like c_f_pointer and c_loc, as well as some utility methods from Joseph Krahn's c_interface_module.

Some functionality is still currently implemented in C, e.g.:

  • errno is a macro on OSX, so we can't just create a Fortran interface for it
  • haven't got around to implementing the signal handling in Fortran, mostly because I don't understand enough about how it works, or how to verify it is working as intended.

Some quirks/deficiences:

  • posix.f90 isn't really properly named, since not all of the interfaces in there are strictly POSIX, I think, and some of the BSD/XNU stuff isn't strictly POSIX compliant.
  • More of the code could probably be moved out of server.c into server.f90.
  • man 3 getaddrinfo, and other documentation, describe addrinfo structs as having ai_canonname after ai_addr but inspection in LLDB shows it coming before, and that layout is the only way to get this code to work.
  • the Fortran code that prepares the call to inet_ntop has to use some ugly workarounds for the fact that calling c_loc on nested derived types is not fully c-interoperable. Also, this code is probably broken for ipv6.

fortran-server's People

Contributors

lukeasrodgers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

thuang

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.