Specialized Topics Continued

Description

Mind Map on Specialized Topics Continued, created by Bhavit Chhatralia on 30/05/2014.
Bhavit Chhatralia
Mind Map by Bhavit Chhatralia, updated more than 1 year ago
Bhavit Chhatralia
Created by Bhavit Chhatralia almost 10 years ago
78
0

Resource summary

Specialized Topics Continued
  1. Networking programming
    1. Essential Concepts
      1. Each system has a virtual "loopback" network adapter
        1. IP range 127.x.x.x is reserved for loopback. Default 127.0.0.1 (localhost)
          1. TCP and UDP use 216 ≈ 65000 ports
            1. Ports 1 – 1024 are reserved and on many systems need admin privileges
              1. A unique port is needed at each part of the communication
                1. Address 0.0.0.0 is used as any/all address
                2. Client Networking (TCP)
                  1. The client initiates the connection by opening a connection to server port
                    1. The client "knows" which ip address and port to use
                      1. The TCP stack takes care of providing two channels (sending and receiving)
                      2. Server Networking
                        1. The server binds for requests on a predefined port on a predefined address (or 0.0.0.0 for all)
                          1. The server then waits for a connection by calling accept to receive a new connection
                            1. Accepted connections get their own local port so that multiple connections are possible
                              1. Server now needs to wait for new connections as well as handle the current one
                              2. Sockets
                                1. Abstraction for network access
                                  1. Origin in Unix
                                    1. Abstracts away from implementation and networking protocol
                                      1. Provides file handles that can be read or written to
                                        1. Sockets don't have a "file" length
                                          1. End of file when connection is closed
                                          2. Client Sockets
                                            1. Specify address family (AF_INET, AF_INET6, AF_UNIX), and address (including port) of destination
                                              1. Local port can be specified, but generally isn't (OS manages this)
                                                1. Connect will initiate the connection
                                                  1. Connection can then be written to or read from.
                                                  2. Server Sockets
                                                    1. Specify address family (AF_INET, AF_INET6, AF_UNIX), and port (and address) to listen to
                                                      1. Accept will wait for a connection and return a new open socket for the connection
                                                        1. Connection can then be written to or read from.
                                                        2. Synchronous Networking
                                                          1. Accept, recv, send (or read, write) are blocking (they return only when finished)
                                                            1. Network operations can be really slow
                                                              1. You might want to do something while waiting (like update the GUI and respond to user events) – so you need threads
                                                              2. Asynchronous Networking
                                                                1. Give commands, the OS handles them
                                                                  1. Callbacks on completion/error
                                                                    1. Polling to see if new data is available
                                                                      1. The only way to do I/O in Javascript
                                                                        1. No synchronization problems (race conditions etc.), but harder programming model.
                                                                        2. Http Basics
                                                                          1. <COMMAND> <PATH> <PROTOCOL> eg: "GET / HTTP/1.1"
                                                                            1. <HEADERS> eg: "Accept-Encoding: gzip"
                                                                            2. Implementation of a server
                                                                              1. Serve "basic" HTTP/1.0
                                                                                1. Ignore most headers
                                                                                  1. Return the request in text/plain
                                                                                  2. Server Workflow
                                                                                    1. Create a new socket. Bound to 0.0.0.0:80
                                                                                      1. While not shutting down
                                                                                        1. accept a new connection
                                                                                          1. Read the first line in the connection
                                                                                            1. Read a line. If it's empty stop processing, If not, add it to the known headers
                                                                                              1. If there is a content-length header. Read the content
                                                                                                1. Process the request based on the path
                                                                                            2. Advanced I/O
                                                                                              1. What is I/O
                                                                                                1. Computers only make sense if they can interact
                                                                                                  1. That means they need to be able to receive inputs
                                                                                                    1. And produce outputs
                                                                                                    2. I/O Devices
                                                                                                      1. Keyboard
                                                                                                        1. Mouse
                                                                                                          1. Screen
                                                                                                            1. Scanner
                                                                                                              1. Printer
                                                                                                                1. Hard Disk
                                                                                                                2. Hardware perspective
                                                                                                                  1. CPU
                                                                                                                    1. Devices live on buses (PCI, USB)
                                                                                                                      1. Buses are middle-men (often layered)
                                                                                                                        1. Devices are exposed in two ways (not exclusive)
                                                                                                                          1. I/O ports (mostly used in Memory Mapped mode)
                                                                                                                            1. Memory access (put video memory into cpu address space)
                                                                                                                          2. I/O ports (on x86 architecture)
                                                                                                                            1. Maximum 32 bits
                                                                                                                              1. Addressed one by one
                                                                                                                                1. In total 65,536 available (each device only gets a limited amount)
                                                                                                                                  1. Ports are unique across a computer (PnP needed to dynamically assign ports)
                                                                                                                                    1. Can be exposed as "plain" memory (memory mapped I/O)
                                                                                                                                    2. Memory based I/O
                                                                                                                                      1. Ports are made available as memory addresses (no longer a big issue with large address spaces)
                                                                                                                                        1. Device based memory is made available in main address space
                                                                                                                                          1. Creates (imperfect) illusion that everything is memory
                                                                                                                                          2. DMA (Direct Memory Access)
                                                                                                                                            1. I/O in many cases is really slow
                                                                                                                                              1. Memory mapped I/O doesn't stop slowness
                                                                                                                                                1. Copying I/O from hardware to memory is a "simple" operation
                                                                                                                                                  1. Special purpose helper system (DMA engine)
                                                                                                                                                    1. Hardware needs to "cooperate" / be designed for it.
                                                                                                                                                    2. OS role
                                                                                                                                                      1. All these technical details are primarily relevant for driver / OS writers
                                                                                                                                                        1. But there are performance and design consequences that leak into programs
                                                                                                                                                      2. Programming I/O
                                                                                                                                                        1. Kinds of I/O
                                                                                                                                                          1. Disk – Arbitrated through File System layer
                                                                                                                                                            1. Video – Arbitrated through windowing system
                                                                                                                                                              1. Audio – Arbitrated through audio layer
                                                                                                                                                                1. Network – Arbitrated through networking layer
                                                                                                                                                                  1. Mouse, Keyboard etc. Arbitrated through windowing system
                                                                                                                                                                    1. General I/O – Arbitrated through device drivers exposing specific or generic interface
                                                                                                                                                                    2. Common thread
                                                                                                                                                                      1. There can only be one program controlling a device
                                                                                                                                                                        1. Many programs want access
                                                                                                                                                                          1. The OS must arbitrate and often control
                                                                                                                                                                            1. Programs receive OS regulated access to smaller abstractions of the device
                                                                                                                                                                            2. I/O Models
                                                                                                                                                                              1. Synchronous – Stop the thread while performing an operation
                                                                                                                                                                                1. Asynchronous – Don't wait for results (but optionally be notified on completion)
                                                                                                                                                                                2. Access Modes
                                                                                                                                                                                  1. Command based – Use special commands to access the I/O device
                                                                                                                                                                                    1. Memory mapped – Get access as if it is a range in memory (where this makes sense) – A bit more complex, but faster, and reuses virtual memory techniques
                                                                                                                                                                                    2. Java
                                                                                                                                                                                      1. Did not use to support many advanced modes
                                                                                                                                                                                        1. With NIO (New IO) supports many more modes
                                                                                                                                                                                        2. I/O Buffering
                                                                                                                                                                                          1. Unbuffered – When using small reads this can be very slow
                                                                                                                                                                                            1. Buffered – Read in large blocks, let users use it as small
                                                                                                                                                                                              1. Unless requesting "direct I/O" always has OS cache between program and file
                                                                                                                                                                                              2. Access modes
                                                                                                                                                                                                1. Read – Only read the file
                                                                                                                                                                                                  1. Write – Remove existing content and write
                                                                                                                                                                                                    1. Append – Add to the end of the file
                                                                                                                                                                                                      1. Random Access – Be able to move through the file (and reading/writing)
                                                                                                                                                                                                        1. Read+ – Read access that does not disallow writing
                                                                                                                                                                                                        2. Files kinds
                                                                                                                                                                                                          1. Binary files. Store sequences of bytes. When storing/reading values larger than bytes, byte order matters (big/small endian)
                                                                                                                                                                                                            1. Text files. Store sequences of characters. Depends on character encoding (mapping bytes in the file to unicode), and line ending
                                                                                                                                                                                                        3. Callbacks and Lambdas
                                                                                                                                                                                                          1. Functors
                                                                                                                                                                                                            1. Literally function objects
                                                                                                                                                                                                              1. Allow functionality to be provided outside object control
                                                                                                                                                                                                                1. In some cases could be replaced with inheritance
                                                                                                                                                                                                                  1. uses
                                                                                                                                                                                                                    1. Comparator<T>
                                                                                                                                                                                                                      1. OnClickListener
                                                                                                                                                                                                                        1. Runnable
                                                                                                                                                                                                                        2. Difference from function
                                                                                                                                                                                                                          1. Function only has address / name
                                                                                                                                                                                                                            1. Functor / function object may have state
                                                                                                                                                                                                                          2. Function ref
                                                                                                                                                                                                                            1. Address to a function
                                                                                                                                                                                                                              1. Type that allows for correct calling
                                                                                                                                                                                                                                1. Since 1.7 there is a MethodHandle in java that “does this”
                                                                                                                                                                                                                                  1. Traditional Method objects are also references
                                                                                                                                                                                                                                    1. In C/C++ it is a pointer (32 or 64 bits) to the address where the executable code starts
                                                                                                                                                                                                                                    2. Poor man's objects (with virtual methods)
                                                                                                                                                                                                                                      1. Struct(ured) type with method pointers
                                                                                                                                                                                                                                        1. The pointed to functions have the object as first parameter, and operate on it
                                                                                                                                                                                                                                          1. The function pointers don't change (or are stored in a shared “class” object)
                                                                                                                                                                                                                                            1. Example
                                                                                                                                                                                                                                            2. 2 kinds of data - java
                                                                                                                                                                                                                                              1. Objects – Always references, inherit from Object, all methods are virtual
                                                                                                                                                                                                                                                1. Primitives – Limited, fixed set of stack based numbers that are the building blocks of everything else
                                                                                                                                                                                                                                                2. Other entities
                                                                                                                                                                                                                                                  1. Classes/types – Have a runtime “existence” through Class objects
                                                                                                                                                                                                                                                    1. Methods – Available through reflection
                                                                                                                                                                                                                                                      1. You can see them, but they are not straightforward (or cheap) to use.
                                                                                                                                                                                                                                                        1. They are second class citizens.
                                                                                                                                                                                                                                                        2. First class functions
                                                                                                                                                                                                                                                          1. When you don't have data
                                                                                                                                                                                                                                                            1. “like static methods”
                                                                                                                                                                                                                                                              1. Parameters can be functions
                                                                                                                                                                                                                                                                1. Functions can return functions
                                                                                                                                                                                                                                                                  1. Other first class "things"
                                                                                                                                                                                                                                                                    1. Primitives
                                                                                                                                                                                                                                                                      1. can be calculated
                                                                                                                                                                                                                                                                      2. Objects
                                                                                                                                                                                                                                                                        1. Can be instantiated (new Object)
                                                                                                                                                                                                                                                                      3. Creating first class functions
                                                                                                                                                                                                                                                                        1. Lambda (λ) (Yes the Greek letter)
                                                                                                                                                                                                                                                                          1. Lambda calculus is a formalisation of programming
                                                                                                                                                                                                                                                                            1. Lambda functions are functions that create functions.
                                                                                                                                                                                                                                                                          2. Why lambda
                                                                                                                                                                                                                                                                            1. Lambda calculus teaches us the awesome power of “dynamic” function creation
                                                                                                                                                                                                                                                                              1. Very compact way to specify functions in-line
                                                                                                                                                                                                                                                                                1. Allows for easy use of very powerful algorithms
                                                                                                                                                                                                                                                                                  1. Use new Thread(() -> { System.out.println(); });
                                                                                                                                                                                                                                                                                  2. Lambda usage
                                                                                                                                                                                                                                                                                    1. map(iterable, function) → new iterable storing the results
                                                                                                                                                                                                                                                                                      1. filter(collection, function) → shortened collection containing only some functions
                                                                                                                                                                                                                                                                                        1. Event handlers
                                                                                                                                                                                                                                                                                          1. Create a function that incorporates a link to an object and calls a method on it as a replacement of a functor.
                                                                                                                                                                                                                                                                                        2. Generics/Templates
                                                                                                                                                                                                                                                                                          1. Core programming concepts
                                                                                                                                                                                                                                                                                            1. Abstraction
                                                                                                                                                                                                                                                                                              1. Handling complexity
                                                                                                                                                                                                                                                                                                1. Code reuse
                                                                                                                                                                                                                                                                                                  1. Using libraries
                                                                                                                                                                                                                                                                                                    1. Designing your own code
                                                                                                                                                                                                                                                                                                    2. Correctness
                                                                                                                                                                                                                                                                                                    3. Design for reuse
                                                                                                                                                                                                                                                                                                      1. Support various uses
                                                                                                                                                                                                                                                                                                        1. Accept any type
                                                                                                                                                                                                                                                                                                          1. Keep code correct
                                                                                                                                                                                                                                                                                                            1. Make types and other things a part of the "parameters" to types and functions
                                                                                                                                                                                                                                                                                                            2. Introspection
                                                                                                                                                                                                                                                                                                              1. Type info available at run-time
                                                                                                                                                                                                                                                                                                                1. Instantiate objects at run-time
                                                                                                                                                                                                                                                                                                                  1. Create method calls at run-time
                                                                                                                                                                                                                                                                                                                    1. Java Class objects
                                                                                                                                                                                                                                                                                                                    2. Code generation
                                                                                                                                                                                                                                                                                                                      1. Special code
                                                                                                                                                                                                                                                                                                                        1. Android's R.java – Link resources to java
                                                                                                                                                                                                                                                                                                                          1. Qt's MOC (Meta Object Compiler) to support a library feature
                                                                                                                                                                                                                                                                                                                          2. Generate code from UML (even round-tripping
                                                                                                                                                                                                                                                                                                                            1. Compiler (generates assembler code)
                                                                                                                                                                                                                                                                                                                            2. Runtime code generation
                                                                                                                                                                                                                                                                                                                              1. Better(reified) generics (C# style)
                                                                                                                                                                                                                                                                                                                                1. Just in time compilation
                                                                                                                                                                                                                                                                                                                                  1. Various Java libraries with Classloader
                                                                                                                                                                                                                                                                                                                                  2. Compile time code generation
                                                                                                                                                                                                                                                                                                                                    1. Special purpose tools
                                                                                                                                                                                                                                                                                                                                      1. One-off programs
                                                                                                                                                                                                                                                                                                                                        1. Framework tools
                                                                                                                                                                                                                                                                                                                                          1. Android R.java
                                                                                                                                                                                                                                                                                                                                            1. JSP processing
                                                                                                                                                                                                                                                                                                                                          2. Generics
                                                                                                                                                                                                                                                                                                                                            1. Allow compiler to enforce rules on types
                                                                                                                                                                                                                                                                                                                                              1. Language specifies type dependencies in classes / functions
                                                                                                                                                                                                                                                                                                                                                1. Only work on types
                                                                                                                                                                                                                                                                                                                                                  1. Generic types are highly related (but not actually the same type)
                                                                                                                                                                                                                                                                                                                                                    1. One body of code
                                                                                                                                                                                                                                                                                                                                                    2. Generic implementation
                                                                                                                                                                                                                                                                                                                                                      1. Type erasure (java) – At run-time generics have disappeared.
                                                                                                                                                                                                                                                                                                                                                        1. Reification (.net) – Remember the used type, allowing for things like arrays of generics (up to having separate implementation for primitives)
                                                                                                                                                                                                                                                                                                                                                        2. What is an object in Java/C#
                                                                                                                                                                                                                                                                                                                                                          1. In place use of objects
                                                                                                                                                                                                                                                                                                                                                            1. Memory usage
                                                                                                                                                                                                                                                                                                                                                              1. In place - Memory is part of owner (object / stack)
                                                                                                                                                                                                                                                                                                                                                                1. Pointer/reference - Separately allocated memory, Owner has a pointer (size does not depend on type)
                                                                                                                                                                                                                                                                                                                                                                2. Templates
                                                                                                                                                                                                                                                                                                                                                                  1. C++ solution to code reuse (especially for containers)
                                                                                                                                                                                                                                                                                                                                                                    1. Unlike generics, is not a type of itself
                                                                                                                                                                                                                                                                                                                                                                      1. Arbitrary specialisations are allowed
                                                                                                                                                                                                                                                                                                                                                                        1. Tells compiler how to create function or class based on parameter type or number
                                                                                                                                                                                                                                                                                                                                                                        2. Example Template
                                                                                                                                                                                                                                                                                                                                                                        Show full summary Hide full summary

                                                                                                                                                                                                                                                                                                                                                                        Similar

                                                                                                                                                                                                                                                                                                                                                                        Mind Maps Essay Template
                                                                                                                                                                                                                                                                                                                                                                        linda_riches
                                                                                                                                                                                                                                                                                                                                                                        Forces and Acceleration
                                                                                                                                                                                                                                                                                                                                                                        Adam Collinge
                                                                                                                                                                                                                                                                                                                                                                        A-level French Vocabulary
                                                                                                                                                                                                                                                                                                                                                                        daniel.praecox
                                                                                                                                                                                                                                                                                                                                                                        English Language Terms
                                                                                                                                                                                                                                                                                                                                                                        ekimlauretta
                                                                                                                                                                                                                                                                                                                                                                        Metallic bonding
                                                                                                                                                                                                                                                                                                                                                                        anna.a.graysmith
                                                                                                                                                                                                                                                                                                                                                                        GCSE Biology, Module B4
                                                                                                                                                                                                                                                                                                                                                                        jessmitchell
                                                                                                                                                                                                                                                                                                                                                                        GCSE AQA Chemistry - Unit 3
                                                                                                                                                                                                                                                                                                                                                                        James Jolliffe
                                                                                                                                                                                                                                                                                                                                                                        Strength and Limitations of research methods
                                                                                                                                                                                                                                                                                                                                                                        Isobel Wagner
                                                                                                                                                                                                                                                                                                                                                                        PSBD TEST 2-2
                                                                                                                                                                                                                                                                                                                                                                        Suleman Shah
                                                                                                                                                                                                                                                                                                                                                                        GCSE Geography - Causes of Climate Change
                                                                                                                                                                                                                                                                                                                                                                        Beth Coiley
                                                                                                                                                                                                                                                                                                                                                                        What You Can Do Using GoConqr
                                                                                                                                                                                                                                                                                                                                                                        Micheal Heffernan