![]() |
| | #1 |
| C Programmer Join Date: Apr 2004
Posts: 477
| Project details: Dedicated 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:
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
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 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. |
| Stack Overflow is offline | |
| | #2 |
| Registered User Join Date: Feb 2003 Location: Mt. Prospect, IL
Posts: 2,602
| 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 |
| axon is offline | |
| | #3 |
| C Programmer 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. |
| Stack Overflow is offline | |
| | #4 | |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,020
| 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. Quote:
| |
| bithub is offline | |
| | #5 | ||
| C Programmer 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:
Quote:
- 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. | ||
| Stack Overflow is offline | |
| | #6 |
| Banned 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. |
| nickname_changed is offline | |
| | #7 | |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,020
| Quote:
| |
| bithub is offline | |
| | #8 |
| Banned Join Date: Feb 2003 Location: Australia
Posts: 986
| That's quite true, I'd forgotten about select() based sockets. |
| nickname_changed is offline | |
| | #9 |
| C Programmer 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. |
| Stack Overflow is offline | |
| | #10 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,020
| whenever you feel comfortable showing off the source, I would be very interested in taking a look |
| bithub is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem Displaying a Struct | rockstarpirate | C++ Programming | 16 | 05-05-2008 09:05 AM |
| project details | kris.c | Tech Board | 8 | 09-14-2006 06:39 AM |
| Game Independent Anti-cheat Project Needs Programmers | GIA Project Lea | Projects and Job Recruitment | 3 | 09-15-2005 07:41 PM |