Skip to content

Instantly share code, notes, and snippets.

@thentenaar
thentenaar / echo-server.c
Created Jan 26, 2015
A very simple, and quickly implemented, echo server
View echo-server.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-2.c
Created Jan 26, 2015
Simple echo server: Refactor #2: Move the work loop into its own function.
View echo-server-2.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-1.c
Created Jan 26, 2015
Simple echo server: Refactor #1: Move the socket setup code into its own function.
View echo-server-1.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*
* Refactor #1 - Move socket creation code into its own
@thentenaar
thentenaar / echo-server-5.c
Created Jan 27, 2015
Simple echo server: Refactor #5: Reduce the depth of nesting in main().
View echo-server-5.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-3.c
Created Jan 26, 2015
Simple echo server: Refactor #3: Change the work loop's while into a do { } while(), and make it smaller
View echo-server-3.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-4.c
Created Jan 27, 2015
Simple echo server: Refactor #4: Replace duplicate returns with goto
View echo-server-4.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-6.c
Created Jan 27, 2015
Simple echo server: Refactor #6: Move the work loop back out into its own function.
View echo-server-6.c
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / sunos-551-paging-bug-fix.c
Created Jul 24, 2015
Patch for the paging bug on Solaris 2.5.1 (SunOS 5.5.1) i386
View sunos-551-paging-bug-fix.c
/**
* Patch to fix the paging bug in the SunOS 5.5.1 (i386) kernel
* Copyright (C) 2015 Tim Hentenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
@thentenaar
thentenaar / gist:4142031
Created Nov 25, 2012
Disassembly of TI BASIC's RND function
View gist:4142031
4F00: ST @>834A,>3F ; Zero loop counter: >3F (63)
4F03: ST @>8310,>4B ; Number buffer address: >834B
4F06: RAND >63 ; Get a pseudo-random number (using 100 as the divisor)
4F08: CZ @>8378 ; If then number isn't zero, goto >4F16
4F0A: BR >4F16
4F0C: DEC @>834A ; Decrement the zero loop counter
4F0E: CZ @>834A ; If the zero loop counter is 0, goto >4F23 (return 0)
4F10: BS >4F23
4F12: BR >4F06 ; Otherwise, continue the loop
4F14: RAND >63 ; Get the next pseudo-random number
@thentenaar
thentenaar / ti-prng.c
Created Nov 25, 2012
Implementation of TI Basic's PRNG
View ti-prng.c
/**
* Implementation of the TI BASIC PRNG
*
* Copyright (C) 2009, Tim Hentenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this