Project details: Dedicated

This is a discussion on Project details: Dedicated within the Projects and Job Recruitment forums, part of the Community Boards category; Hello, I am currently working on a small project. I'm not looking for recruitment at the moment, rather just spreading ...

  1. #1
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477

    Project details: Dedicated

    Hello,

    I am currently working on a small project. I'm not looking for recruitment at the moment, rather just spreading word and ideas about my upcoming programming endeavors.

    Project Overview
    My current project, Dedicated, is a small dedicated server which consists of 5 categories:
    • Server handling
    • Client handling
    • Error handling
    • Configuration
    • Allocation

    It has been under-development for nearly 2 months, and has performed well. It was written in the C language. I intend to make sure the build doesn’t produce one error or warning. Also, throughout all of the code I have error checking and improvise no memory leakage.


    Project Details
    » The Server handling category is the most crucial. I handle all incoming connections and data received with select(). Once a client connects, a new hash will be created within a dynamically created hash-table. The Server allows x amount of clients to connect, which is set to 8 automatically or manually if ran with the configuration options.

    » The Client handling category handles all client information. It consists of a hash-table that is dynamically created. Each time a new client is stored, all other pertinent information is included in their node. Including IP, port, socket, name, etc…

    » The Error handling category is more crucial than anything else. With detailed consideration, I have created a custom error handling system. This system works like fprintf(), whereas the first parameter can either be a warning or error. If found as an error, it will free all memory used [discussed in Allocation handling].

    » The Configuration category is handy in almost any program. I allow people to see a detailed look at the configuration options by using the –help command:
    Code:
    usage: dedicated [options]
    dedicated options:
        --config-file=file    configuration file
        --debug               debug allocation run-time
        --hunkSize=n          custom hunk size [MB]
        --slots=x             connection slots
        --conntype=TCP        connection type, i.e., UDP/TCP
        --port=10110          server port number
        --version             displays version
        --help                 for help
    The current version my Dedicated is 0.1.3, and is solely maintained by me. I allow configuration files that look similar to the following:
    Code:
    #
    # Dedicated Configuration
    #
    
    # Define a custom port
    # All ports can range between 5000 and 50000
    #port "10110"
    
    # Server Connection Type
    # TCP or UDP
    #conn "TCP"
    
    # Maximum amount of client slots
    # Between 0 and 32
    slots "6"         
    
    # Run in debug mode
    # Set to 1 or run with --debug flag
    #debug "1"
    The debug flag displays all allocations being made, including the free instances. This can be handy if any Segmentation Fault’s occur.

    » The Allocation category was by far the most difficult. It has a working strategy, and has deemed useful in this project. The hunkSize option allows you to set an amount of space you want to pre-allocate. When the program is first executed, it splits the bytes in two and allocates memory to 2 heaps. If one heap exceeds its limit, it automatically switches to the other.

    The allocation system works as it partitions out blocks of our memory heap, so we can re-use the same memory without further allocation from the core. Also, for error checking, I store all allocations made in a table so that I can check for duplicate addresses. Once freed, the memory can be used again appropriately. This alone took over 1 month to accomplish.

    Overall, the project runs as a server. Clients can connect, and stored in a hash table. I can look them up, send data to them, and free the hash when finished. With allocation in mind, I created one function that will free all existing memory used within our heap for good practice. If anything fails, the program can automatically free all memory including the heaps.

    When any error occurs, and I send a FATAL message to the program, all allocations will be freed accordingly. When executed with Valgrind, I receive little to no errors during run-time and when exited it reports no memory leaks or malloc’d blocks.


    Conclusion
    Another addition was to allow input from the server locally. So far, there are 2 commands that work: “connections” and “quit”. If ran in Debug mode, you can use the “allocation” command which will print the current amount of allocated bytes being used.

    The project’s development is coming along nicely. It has been tested on Slackware 10.0 and GCC 3.4.3. With flags -O2, -Wall, -ansi, -pedantic, -pedantic-errors, and -std=c89 . No warnings and no errors. As of the time being, I’m out of ideas at the moment. I will soon purchase a UNIX Network Programming book to further improve my current operations. If anyone has any comments, or ideas, for my project please let me know. All feedback is welcomed.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Looks somewhat interesting Stack; I know that Sean has been working on a server project as well - you guys might want to hook up.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Alright,

    Cool. I'll keep that in mind. My strong-point is pure C, not networking at the moment. Does anyone know if Sean has posted information about his project? Also, I'm considering setting up CVS. Though, I just haven't found the time to learn the configuration, etc...


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    I believe sean was working on a webserver if I remember correctly.

    I myself have done a few different server projects which sound similar to what you are doing. I've always prefered the multi threaded approach rather than using select(), but that's just because it's always been easier for me to control each client connection that way.

    So do you have an application in mind for this server, or is it just a generic server project which can be used for different things?

    I'd be interested in seeing what you have. I never went into as much detail as you with memory allocation, so I'd like to see your implementation.

    When the program is first executed, it splits the bytes in two and allocates memory to 2 heaps. If one heap exceeds its limit, it automatically switches to the other.
    What is the purpose of using two heaps? Is it for the extra speed you get with a smaller heap size?

  5. #5
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Hello,

    I've heard that the Multi-threaded approach can be useful. So far, I am in the blue of how it operates. Though, as soon as I pick up that Network Programming book I plan to overhaul my connection system. As of the moment, I use a hash-table to store all of the incoming and current connections. I can look a client up by the socket the server has assigned to them. I also dynamically store further information per hash. Once I look up the socket, it returns the hash node. Once a client disconnects, I free all existing memory of the node.

    Quote Originally Posted by bithub
    What is the purpose of using two heaps? Is it for the extra speed you get with a smaller heap size?
    » Well, for safety measures. For instance, you ask my program to pre-allocate 3MB. The allocation system will convert the MB to bytes, 3,145,728 bytes, and divide it by 2: 1,572,864. Each heap instance allocates that amount of space to it. If one fills up, it automatically switches to the other. To make things simpler, my "heap" is a structure that holds a "void *" pointer in it. My alloc sequence can partition out a certain size of that pointer when requested.

    Quote Originally Posted by bithub
    I'd be interested in seeing what you have. I never went into as much detail as you with memory allocation, so I'd like to see your implementation.
    » Ah, well I may release the source code as soon as I fix a few problems with it. Or I'll just release a beta.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Multithreaded networking is usually when you have one thread that listens, and each time a connection is made a new thread is spawned that handles the connection then dies. Microsofts IIS Web Server works like this (IIRC). There is one main "listener" thread that sets up the application and sits there monitoring the ports, and whenever a new connection is made it starts a worker thread to handle the connection and then the thread dies (in a nutshell).

    Then you can do pooling, where you start the listener and say 20 worker threads. The worker threads never die, they handle a connection and then just sit around waiting for another connection. This usually makes things faster (for the first 20 connections).

    By not using multithreaded networking, you're limiting yourself to just one connection at a time - they connect, you handle the request and then you listen again. What if someone connects and goes idle? Everyone else has to wait. It's especially powerful on hyperthreaded processors.

    I wrote the SWEBS Web Server a while ago and I was thinking about putting all the stuff I learned about sockets into an article online. If you're interested let me know and I'll see what I can do.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    By not using multithreaded networking, you're limiting yourself to just one connection at a time - they connect, you handle the request and then you listen again.
    That's not true. You can use the select() function to handle multiple connections on one thread. There are a lot of servers out there that use this technique.

  8. #8
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    That's quite true, I'd forgotten about select() based sockets.

  9. #9
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Ah,

    As of now, I'm using select() based sockets. I intend to research multi-threaded sockets in the near future.

    bithub: You previously stated that you'd be interested in viewing my memory allocation methods. I'm not certain of the source release date, though I could let you see my current development. Keep in mind, It's still undergoing development.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    whenever you feel comfortable showing off the source, I would be very interested in taking a look

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 10:05 AM
  2. project details
    By kris.c in forum Tech Board
    Replies: 8
    Last Post: 09-14-2006, 07:39 AM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21