nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

Re: inotify e lettura di strutture dati da file descriptor

Von: Max M. (edgar@maxim.comm2000.it) [Profil]
Datum: 26.01.2008 22:43
Message-ID: <14GdnXEMea-tNAbanZ2dnUVZ8sylnZ2d@kpnqwest.it>
Newsgroup: it.comp.os.linux.development
Vito.DeTullio@gmail.com wrote:
> prima di tutto, grazie! Senza di te non avrei mai colto che read
> poteva restituire anche più strutture di fila!

Ma è scritto nella manpage (io non ho mai usato inotify in vita mia).
Consiglio di leggere bene la documentazione prima di scrivere codice.
Ci sono in giro anche molti articoli su questo argomento.
Questo mi pare buono: http://www.linuxjournal.com/article/8478 .

>
> cosa mi sfugge?

Ti sfugge una regola dell'aritmetica dei puntatori. Se 'p' è un puntatore,
quando scrivi 'p += n' sposti 'p' di ( n * sizeof(*p) ) byte, non di n byte
(a meno che sizeof(*p) non valga 1).

Quindi se scrivi 'events += dimensioni_struttura', non ottieni quello che
desideri.

Dovresti fare qualcosa del genere:

char buffer[ MAX_SIZE ];
int count = read( fd, buffer, sizeof(buffer) );
int offset = 0;
while( offset < count )
{
struct inotify_event* event = (struct inotify_event*)(buffer+offset);
// leggi event ...
offset += sizeof(struct inotify_event) + event->len;
}

Max



[ Auf dieses Posting antworten ]