PDA

View Full Version : C -> vb.net


Kralizek
07-01-2004, 20:32
chi mi può dare una mano a tradurre questa funzione dal c a vb.net ??

in realtà a me serve una funzione che faccia uqello che fa questa
funzione... quindi anche se non è la traduzione esatta... thk


int read_line(int newSd, char *line_to_return) {

static int rcv_ptr=0;
static char rcv_msg[MAX_MSG];
static int n;
int offset;

offset=0;

while(1) {
if(rcv_ptr==0) {
/* read data from socket */
memset(rcv_msg,0x0,MAX_MSG); /* init buffer */
n = recv(newSd, rcv_msg, MAX_MSG, 0); /* wait for data */
if (n<0) {
perror(" cannot receive data ");
return ERROR;
} else if (n==0) {
printf(" connection closed by client\n");
closesocket(newSd);
return ERROR;
}
}

/* if new data read on socket */
/* OR */
/* if another line is still in buffer */

/* copy line into 'line_to_return' */
while(*(rcv_msg+rcv_ptr)!=END_LINE && rcv_ptr<n) {
memcpy(line_to_return+offset,rcv_msg+rcv_ptr,1);
offset++;
rcv_ptr++;
}

/* end of line + end of buffer => return line */
if(rcv_ptr==n-1) {
/* set last byte to END_LINE */
*(line_to_return+offset)=END_LINE;
rcv_ptr=0;
return ++offset;
}

/* end of line but still some data in buffer => return line */
if(rcv_ptr <n-1) {
/* set last byte to END_LINE */
*(line_to_return+offset)=END_LINE;
rcv_ptr++;
return ++offset;
}

/* end of buffer but line is not ended => */
/* wait for more data to arrive on socket */
if(rcv_ptr == n) {
rcv_ptr = 0;
}

} /* while */
}