11-23-2010
I am not familiar with this particular error. I am running Ubuntu, and I looked at the man page for setsockopt. It can return EINVAL, which may be the error you receive. Teh reason for this error is that optlen (the last parameter) is invalid. Sometimes also when the optval is invalid.
In your specific code I detected two problems:
1. You didn't zero timeout.tv_usec. Perhaps it contained a garbage value that is invalid (too big).
2. The casting you are doing in the call itself do not conform to the definition of setsockopt(). Instead of (struct timeval *) use (void *). For the last parameter, I would use the cast (socklen_t).
10 More Discussions You Might Find Interesting
1. Programming
how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries
through a c program or java program
i want to store that data into database so i can show it graphically
thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies
2. Programming
Please tell me solaris functions/api for getting following information
1- Function that tells how much memory used by current process
2- Function that tells how much memory used by all running processes
3- Function that tells how much CPU is used by current process
4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies
3. HP-UX
how can I find cpu usage memory usage swap usage and
I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times
my final destination is monitor process
logical volume usage above X % and number of Logical voluage above
can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies
4. Solaris
Hi,
I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP.
I want the oids for above tasks.
can you please tell me that
Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies
5. AIX
How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies
6. Shell Programming and Scripting
Hi All
I am not able to understand the usage of d# in the below variable declaration.
FILE_LOC contains the directory path
And also help me to know about what will be saved in the variable j.
Thanks!!!
j=${d#${FILE_LOC}/} (2 Replies)
Discussion started by: mohanm
2 Replies
7. UNIX for Dummies Questions & Answers
Hi all,
Can you please tell me the command, with which one can know the amount of space a specific directory has used.
df -k . ---> Displays, the amount of space allocated, and used for a directory.
du -k <dir name> - gives me the memory used of all the files inside <dir>
But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies
8. Programming
I create a program that need a timeout on both send() and recv() function, but I found that SO_SNDTIMEO doesn't work but SO_RCVTIMEO works!!
int sock;
int bytesRcvd, totalBytesRcvd = 0;
struct sockaddr_in servAddr;
struct timeval tv;
int rx = 0;
int tx... (1 Reply)
Discussion started by: sehang
1 Replies
9. Shell Programming and Scripting
I recently came across this construct that i am not able to understand.
ex: cat $(grep -l 'HELLO' *)
the above command prints out the contents of the file if HELLO string is present in the file. I am not able to understand the usage of "$(" here.. can anybody help me understand this? $anything... (2 Replies)
Discussion started by: sreeharshasn
2 Replies
10. UNIX for Dummies Questions & Answers
Let's say i have 20 users logged on Server. How can I know how much memory percent used each of them is using with system time in each user? (2 Replies)
Discussion started by: roy1912
2 Replies
LEARN ABOUT NETBSD
timespec_to_timeval
TIMEVAL(3) BSD Library Functions Manual TIMEVAL(3)
NAME
timeval, timespec, itimerval, itimerspec, bintime -- time structures
SYNOPSIS
#include <sys/time.h>
void
TIMEVAL_TO_TIMESPEC(struct timeval *tv, struct timespec *ts);
void
TIMESPEC_TO_TIMEVAL(struct timeval *tv, struct timespec *ts);
DESCRIPTION
The <sys/time.h> header, included by <time.h>, defines various structures related to time and timers.
1. The following structure is used by gettimeofday(2), among others:
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
The tv_sec member represents the elapsed time, in whole seconds. The tv_usec member captures rest of the elapsed time, represented as
the number of microseconds.
2. The following structure is used by nanosleep(2), among others:
struct timespec {
time_t tv_sec;
long tv_nsec;
};
The tv_sec member is again the elapsed time in whole seconds. The tv_nsec member represents the rest of the elapsed time in nanosec-
onds.
A microsecond is equal to one millionth of a second, 1000 nanoseconds, or 1/1000 milliseconds. To ease the conversions, the macros
TIMEVAL_TO_TIMESPEC() and TIMESPEC_TO_TIMEVAL() can be used to convert between struct timeval and struct timespec.
3. The following structure is used by setitimer(2), among others:
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
4. The following structure is used by timer_settime(2), among others:
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
Both struct itimerval and struct itimerspec are used to specify when a timer expires. Generally, it_interval specifies the period
between successive timer expirations. A value zero implies that the alarm will fire only once. If it_value is non-zero, it indicates
the time left to the next timer expiration. A value zero implies that the timer is disabled.
5. The following structure is used by bintime(9), among others:
struct bintime {
time_t sec;
uint64_t frac;
};
The sec member specifies the time in seconds and frac represents a 64-bit fraction of seconds. The struct bintime is meant to be used
in the kernel only. It is further described in timecounter(9).
EXAMPLES
It can be stressed that the traditional UNIX timeval and timespec structures represent elapsed time, measured by the system clock (see
hz(9)). The following sketch implements a function suitable for use in a context where the timespec structure is required for a conditional
timeout:
static void
example(struct timespec *spec, time_t minutes)
{
struct timeval elapsed;
(void)gettimeofday(&elapsed, NULL);
_DIAGASSERT(spec != NULL);
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
/* Add the offset for timeout in minutes. */
spec->tv_sec = spec->tv_sec + minutes * 60;
}
A better alternative would use the more precise clock_gettime(2).
SEE ALSO
timeradd(3), tm(3), bintime_add(9)
BSD
April 12, 2011 BSD