How do I copy or rewind *argv[]


 
Thread Tools Search this Thread
Top Forums Programming How do I copy or rewind *argv[]
# 15  
Old 08-05-2011
Thank you very much.
My last question is, do you have any suggested methods of receiving data that you could post? I
have read that I can use something similar to "if(FD_ISSET(i, &read_fds) && i != simpleSocket)"
but do you know of any other methods you would recommend. It works so awesome
at the moment.

---------- Post updated at 06:31 AM ---------- Previous update was at 06:29 AM ----------

Also if anyone wants me to post the entire server, which as of right now is just a main statement
with a couple of functions, I will be glad to. It works great and I would be glad to explain parts of
it to anyone.

---------- Post updated at 05:43 PM ---------- Previous update was at 06:31 AM ----------

Is there any chance you could show me how to check the write_fds set for write block after running
it through the select function?
# 16  
Old 08-05-2011
Typically I maintain a list of structures where each represents a session. For each pass through the "select loop" I set the readfd corresponding to each connected session and call select(). When select returns, I loop across each session structure to see if the select indicated data ready and read the data if it's there. Similar to what you are doing.

A potential issue is that the data received may not be complete, or it may have multiple complete "things." If, for instance, your application is expecting zero terminated strings as a "thing" the data read may contain multiple things with one partial thing at the end. You will have to write code that saves the partial thing and joins it with the first part of the next data read from that session. Not difficult, just tedious.

Checking to see if a write() will block is nearly the same as checking for data ready. Set the fd list for each session you want to write to and then invoke select(). Test the write fd list for each fd, and any that is set can be written to without blocking.

Similarly to piecing back together partial buffers when reading, if you don't want the write to block, you'll need to save the data to be sent in a queue, and manage sending it at some future time when the session isn't blocking. Again, not difficult, but tedious to implement.

Getting your hands dirty with this level of socket programming is good experience, but if you're looking for something that might handle this layer of the communications for you, check out 0MQ (Zero-MQ):

The Intelligent Transport Layer - zeromq
# 17  
Old 08-06-2011
Thank you so very much. Here is a link you might enjoy. I really liked looking it over.
select_tut(2): synchronous I/O multiplexing - Linux man page
This User Gave Thanks to Errigour For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ARGV how to use it?

So i am trying to read in file readFile <GivenFile> modFile looking for a regular file under the directories in the GivenFile and print them out is my over all goal. basically I am looking for anything that looks like a directory in the given file and printing it out. Since I am trying to do... (2 Replies)
Discussion started by: squidGreen
2 Replies

2. UNIX for Advanced & Expert Users

O argv, argv, wherefore art thou argv?

All of my machines (various open source derivatives on x86 and amd64) store argv above the stack (at a higher memory address). I am curious to learn if any systems store argv below the stack (at a lower memory address). I am particularly interested in proprietary Unices, such as Solaris, HP-UX,... (9 Replies)
Discussion started by: alister
9 Replies

3. Programming

help with C, argv

when i run my program, i have a parameter, that i want to set the value to another string i am using int main(int argc, char **argv) { char my_str=argv; printf("%s",my_str); return 0; } and i get Segmentation fault ran using ./my_prog /usr/share/dict/words hello1 ... (2 Replies)
Discussion started by: omega666
2 Replies

4. Programming

ARGV help in C

Hi, Can somehelp help how to list file in a dir? (5 Replies)
Discussion started by: Learnerabc
5 Replies

5. UNIX for Dummies Questions & Answers

Need help to understand cpio and no rewind tapes

SCO openserver 5r5 I only have this available to me ... To list the files... cpio -itcvB < /dev/nrct0 To copy a file out cpio -icvdBum filename < /dev/nrct0So cpio is to archive or "zip" files up?? and /dev/nrct0 is the tape drive ??? How can i list all the files inside... (2 Replies)
Discussion started by: khaos83_2000
2 Replies

6. Shell Programming and Scripting

if #argv = (this OR that) then...

this is in one of my scripts... if ($#argv == 0) then echo 'blah bla' exit 0 endif I want it to be something like this... if ($#argv == 0 OR $argv >=3) echo 'blah bla' exit 0 endif so when the arguments are none, or greater than three I want this "if then" to take over. how? I... (5 Replies)
Discussion started by: ajp7701
5 Replies

7. Programming

Problem with fgets and rewind function ..

Hello Friends, I got stuck with fgets () & rewind() function .. Please need help.. Actually I am doing a like, The function should read lines from a txt file until the function is called.. If the data from the txt file ends then it goes to the top and then again when the function is called... (1 Reply)
Discussion started by: user_prady
1 Replies

8. Programming

help for argv argc

Hi C experts, I have the following code for adding command line option for a program int main (argc, argv) int argc; char *argv; { char *mem_type; //memory type char *name; //name of the memory int addr; //address bits int data; ... (5 Replies)
Discussion started by: return_user
5 Replies

9. UNIX for Dummies Questions & Answers

What is the function of rewind()?

What is the function of rewind()? (2 Replies)
Discussion started by: tigerkin
2 Replies

10. Programming

argv

I have a program which I wish to modify. It used to be run from the command line, but now I wish to change this so it can be used as a function. The program has complex argument processing so I want to pass my paramters to as if it were being called by the OS as a program. I have tried to... (2 Replies)
Discussion started by: mbb
2 Replies
Login or Register to Ask a Question