How to detect a delimiter while reading from a socket file descriptor in C? -


in c, while reading buffer socket file descriptor, how make read stop if delimiter detected? let's assume delimiter '>' character.

read(socket_filedes, buffer, maxsz); /* stop if delimiter '>' detected */ 

the read() function not examine data transfers them source buffer. cannot force stop transferring data @ specific character or characters if not otherwise have stopped there.

on other hand, important recognize read() not read full number of bytes specified in case. on 1 hand, means need prepared run read() calls in loop collect data expect, on other hand means can expect if read() has transferred @ least 1 byte return when no more data available transfer. thus, if sender stops sending data after delimiter, read() stop reading after delimiter.

if cannot rely on sender break transmission require, have option of reading 1 byte @ time. can awfully inefficient, however. more usual solution job in 2 stages: (1) perform fast, block-wise read()s kernel userspace buffer, , (2) parse buffer contents via userspace code. readable c streams when using buffer.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -