difference send and Write - Networking

This is a discussion on difference send and Write - Networking ; Hullo, In socket programming,i read send is similar to write, if flag is set as 0 in send. but I have seen one difference. the retval is 0 in case of write and in case of send it is the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: difference send and Write

  1. difference send and Write

    Hullo,
    In socket programming,i read send is similar to write, if flag is set
    as 0 in send.
    but I have seen one difference.
    the retval is 0 in case of write and in case of send it is the number
    of bytes sent (with flag zero)
    Why so?

    if (rval = write(msgsock, DATA, sizeof(DATA)) < 0){
    printf("no. of bytes written %d\n",rval); // zero here
    if((rval = send(msgsock,DATA,sizeof(DATA),0)) < 0){
    printf("no. of bytes written %d\n",rval); // sizeof(DATA) here

    One more question.
    Is the return value indicates the number of bytes send on wire OR
    number of bytes copied to kernel send buffer?

    NOTE: this is for SOCK_STREAM socket in linux 2.6
    Thanks.


  2. Re: difference send and Write

    SaranJothy wrote:
    > Hullo,
    > In socket programming,i read send is similar to write, if flag is set
    > as 0 in send.
    > but I have seen one difference.
    > the retval is 0 in case of write and in case of send it is the number
    > of bytes sent (with flag zero)
    > Why so?


    It isn't true; write() returns the number of bytes written (if it writes
    bytes).

    Robert

    >
    > if (rval = write(msgsock, DATA, sizeof(DATA)) < 0){
    > printf("no. of bytes written %d\n",rval); // zero here
    > if((rval = send(msgsock,DATA,sizeof(DATA),0)) < 0){
    > printf("no. of bytes written %d\n",rval); // sizeof(DATA) here
    >
    > One more question.
    > Is the return value indicates the number of bytes send on wire OR
    > number of bytes copied to kernel send buffer?
    >
    > NOTE: this is for SOCK_STREAM socket in linux 2.6
    > Thanks.
    >


+ Reply to Thread