파일 전송 프로그램 구현도중 알수 없는 무한루프가 발생합니다.

khm915의 이미지

리눅스 TCP상에서 표준 입출력 함수를 이용(입력, 출력 분리)하여

파일을 전송하는 프로그램(클라이언트에서 서버로 파일전송)을 만들고 있습니다.

리눅스 시스템콜을 사용했을때에는 문제가 없던 소스 였는데 파일 send,recv 쪽을 표준 입출력 함수인 fread 와 fwrite 로 바꾸니

클라이언트에서는 파일을 다 전송했다고 출력되는데 서버에서는 무한루프에서 빠져나오지 못하고 있습니다.

파일 전송을 위해 사용한 방법은 fread의 반환값을 검사(제가 알기로는 읽은 파일길이를 반환)하여

그 값이 0보다 클때까지 파일을 전송하고, 서버쪽에서는 fread의 반환값을 검사하여 그 값이 0보다 크면

파일을 써주고 미리 정해진 버프 사이즈보다 받은 파일의 사이즈가 적을경우 무한루프를 종료하게 하였습니다.

고수님들의 지도 편달 부탁드립니다!!~

<서버>
while(1)
	{
		numread = fread(file_recv, 1, FILE_BUFSIZE, readFP);	//file recv
 
		printf("\nFile Recevice : %d Bytes \n", numread);
		if(numread > 0) 	//반환값검사
		{
			fwrite(file_recv, 1, numread, fp);		//recv data write
			numtotal += numread;			//read한 data byte 합계
			printf("File Total Recevice : %d Bytes \n", numtotal);	
		}
		else
		{
			printf("파일 전송 에러");
			break;
		}
		//read한 data의 값이 file_buffsize 보다 작으면
		//마지막 데이터로 간주 while문 중지
		if(numread < FILE_BUFSIZE) break;		 
	}

<클라이언트>
while(1)
	{	//file_buffsize  만큰 읽어 file_send 버퍼에 저장
		numread = fread(file_send, 1, FILE_BUFSIZE, fp); //fread return 
		printf("%d. File Send %d Byte\n", i, numread);
		if(numread > 0) 	//반환값검사
		{
			fwrite(file_send, 1, numread, writeFP);	//file
			numtotal += numread;	//write한 data byte 합계
		}
		else if(numread == 0 && numtotal == totalbytes) 
		{
			printf("File Trans Complete : %d Bytes\n", numtotal);
			fwrite(file_send, 1, 0, writeFP);
			break;
		}
		else 
		{
			printf("파일 전송 에러");
                        break;
		}
		i++;
	}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.