5

I have downloaded the sytem source code from here, but i can't find source code of read/write functions from the package. Could anybody tell me where I can get the code for these socket operation functions?

[why I want to check the source code]
I am developing a multithreaded linux application and need to know, if calling socket operation functions like write/read/sendmsg to access a same TCP socket from different threads concurrently is safe or not.

durron597
  • 31,968
  • 17
  • 99
  • 158
Wallace
  • 561
  • 2
  • 21
  • 54
  • It's a duplicate of http://stackoverflow.com/questions/1981372/are-parallel-calls-to-send-recv-on-the-same-socket-valid – deufeufeu May 25 '13 at 09:46
  • @deufeufeu I also read this post before making my own thread, but I am not satisfied with the anwser it provided, so I decided to check the source code myself:_) – Wallace May 26 '13 at 04:24

2 Answers2

7

you can search a function and other things in the kernel source code on LXR.

But before you search, you should know that write/read/sendmsg are system call,and their definitions aren't like usually functions. When you use read(), sys_read() works in fact,and itselves defintion is also confused:here

here is write() and sendmsg() .

If you want to know more about system call such as their definiton, you can read chapter.5 of Linux Kernel Development.

vvy
  • 1,963
  • 13
  • 17
4

1) Find out what library provides function you want to see source of

e.g. "man read"

NAME
   read - read from a file descriptor

SYNOPSIS
   #include <unistd.h>

   ssize_t read(int fd, void *buf, size_t count);

2) locate header file, e.g. "/usr/include/unistd.h"

3) find out what package provides this file, with Debian/Ubuntu e.g.

pwadas@kehillah:~$ dpkg -S /usr/include/unistd.h 
libc6-dev: /usr/include/unistd.h

4) Download source package and browse code

there's probably many "read" functions available from various libraries. You might want to try

man 7 socket
man 7 tcp 

or other relevant sources.

Piotr Wadas
  • 1,838
  • 1
  • 10
  • 13